Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set foreground service type to FOREGROUND_SERVICE_TYPE_LOCATION #970

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

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
2 participants