Skip to content

Foreground service notification appears with delay 10s in Android 12 (SDK 31) #560

@andkom

Description

@andkom

Your Environment

  • Plugin version: 0.6.3
  • Platform: Android
  • OS version: 12
  • Device manufacturer and model: Samsung
  • Running in Simulator:
  • React Native version: 0.66.4
  • Plugin configuration options:
  • Link to your project:

Context

In Android 12 there is UX delay for foreground service notifications:

"To provide a streamlined experience for short-running foreground services, devices that run Android 12 or higher can delay the display of foreground service notifications by 10 seconds, with a few exceptions. This change gives short-lived tasks a chance to complete before their notifications appear."

Services that show a notification immediately
If a foreground service has at least one of the following characteristics, the system shows the associated notification immediately after the service starts, even on devices that run Android 12 or higher:

The service is associated with a notification that includes action buttons.
The service has a foregroundServiceType of mediaPlayback, mediaProjection, or phoneCall.
The service provides a use case related to phone calls, navigation, or media playback, as defined in the notification's category attribute.
The service has opted out of the behavior change by passing FOREGROUND_SERVICE_IMMEDIATE into setForegroundServiceBehavior() when setting up the notification."

Expected Behavior

When service starts, foreground service notification appears without dalay

Actual Behavior

When service starts, foreground service notification appears with 10s delay

Possible Fix

Set notification's category to CATEGORY_NAVIGATION in https://github.com/mauron85/background-geolocation-android/blob/58464febf6901f1e489817e4425418d48443929b/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java#L70

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    builder.setCategory(Notification.CATEGORY_NAVIGATION);
}

Steps to Reproduce

Context

Debug logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions