android / health-samples

Apache License 2.0
248 stars 142 forks source link

Issue start service at foreground when update targetSdk = 34 #276

Open lambui09 opened 3 weeks ago

lambui09 commented 3 weeks ago

java.lang.RuntimeException: Unable to bind to service com.everfit.service.ExerciseService@bbeb578 with Intent { Caused by: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { cmp=com.everfit.debug/com.everfit.service.ExerciseService }: app is in background uid UidRecord

yschimke commented 3 weeks ago

Is it this change?

https://developer.android.com/training/wearables/versions/5/changes#exercise-recording-fgs-type

      <!-- If your app can also monitor location information, use
           android:foregroundServiceType="health|location" instead. -->
      <service
          android:name=".MyExerciseSessionRecorder"
          android:foregroundServiceType="health">
      </service>
lambui09 commented 3 weeks ago

image I update it, but same issue.

    <service
        android:name=".service.ExerciseService"
        android:enabled="true"
        android:exported="true"
        android:foregroundServiceType="health"
        android:permission="android.permission.FOREGROUND_SERVICE_HEALTH" />
yschimke commented 2 weeks ago

Try this change https://github.com/android/health-samples/pull/277

I'll see if we need to update the docs