Skip to content

Set foreground service type to FOREGROUND_SERVICE_TYPE_LOCATION - #970

Closed
ecarrara wants to merge 1 commit into
Lyokone:masterfrom
buserbrasil:sdk-34-support
Closed

ecarrara wants to merge 1 commit into
Lyokone:masterfrom
buserbrasil:sdk-34-support

Conversation

@ecarrara

Copy link
Copy Markdown

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

@avelino avelino left a comment

Copy link
Copy Markdown

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
Copy Markdown

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.

Lyokone added a commit that referenced this pull request Jul 14, 2026
Android 14 (API 34) throws when a foreground service starts without
declaring a type. Uses ServiceCompat.startForeground with
FOREGROUND_SERVICE_TYPE_LOCATION on API 29+ and declares the
FOREGROUND_SERVICE / FOREGROUND_SERVICE_LOCATION permissions in the plugin
manifest so background location works on modern Android (#970).
@Lyokone

Lyokone commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Thanks for this. Closing as superseded — setting the foreground service type is already handled in the current Kotlin FlutterLocationService.kt. Appreciate the contribution.

@Lyokone Lyokone closed this Jul 17, 2026
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

4 participants