GeoTecINIT / WearOSSensors

Reliable and concurrent access to smartwatch's sensors
Apache License 2.0
18 stars 4 forks source link

Starting Android sdk 34, apps should declare foreground service types #11

Closed Eagleseb closed 10 hours ago

Eagleseb commented 10 hours ago

Hello, thanks for writing this library. I'm trying to set it up for a wearos app aiming at collecting health data during clinical studies. It turns out the app crashes on most recent watches because the foreground service does not declare the "health" service type.

the following should be added to the app manifest:

<service
            android:name="es.uji.geotec.wearossensors.services.WearSensorRecordingService"
            android:exported="true"
            android:foregroundServiceType="health" />

and the services started with the following:

       ServiceCompat.startForeground(
            /* service = */ this,
            /* id = */ 100, // Cannot be 0
            /* notification = */ notification,
            /* foregroundServiceType = */
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                ServiceInfo.FOREGROUND_SERVICE_TYPE_HEALTH
            } else {
                0
            },
        )

as per https://developer.android.com/develop/background-work/services/foreground-services#fgs-prerequisites I can open a PR with the changes if the project is still active when I get some time to test it.

Eagleseb commented 10 hours ago

Never mind, it seems that startForeground starts services with FOREGROUND_SERVICE_TYPE_MANIFEST by default and so adding the service entry to the manifest is sufficient. No need for a PR, closing issue.

Thanks!

matey97 commented 8 hours ago

Hi @Eagleseb, thanks for reporting the issue. I already had this issue in mind and worked some time ago on the fix, but I didn't release a new version. I'll release v1.3.0 with the service types included in the library's manifest.

Eagleseb commented 7 hours ago

that's great, thanks for the fast answer and fix!