Skip to content

Conversation

@ecarrara
Copy link

This PR include foreground service type FOREGROUND_SERVICE_TYPE_LOCATION at runtime, the Android SDK 34 requires it.

(...)
Note: Beginning with SDK Version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE, apps targeting SDK Version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE or higher are not allowed to start foreground services without specifying a valid foreground service type in the manifest attribute android.R.attr#foregroundServiceType. See Behavior changes: Apps targeting Android 14 for more details.

https://developer.android.com/reference/kotlin/android/app/Service#startforeground

Fix #924 and #954

Copy link

@avelino avelino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like calling the same function twice in an if condition, using if in parameters is common in Kotlin

startForeground(
  ONGOING_NOTIFICATION_ID,
  notification,
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) FOREGROUND_SERVICE_TYPE_LOCATION else 0
)

ref https://developer.android.com/develop/background-work/services/foreground-services#start

@argenkiwi
Copy link

Does it actually fix #954? I have a project of my own that faces the same issue on Samsung devices running Android 14 and the FOREGROUND_SERVICE_TYPE_LOCATION is being set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background geolocation has not worked since Android version 13

3 participants