question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UAMP crashes with ForegroundServiceStartNotAllowedException when targeting API 31/32

See original GitHub issue

The UAMP app crashes when trying to resume the playback session using the Google Assistant if the target and compile sdk is 31 or above

Steps to reproduce it:

  • Checkout the latest version of uamp and update the target and compile sdk to API 31 or 32
  • Fix the compilation issues (adding flags to the manifest and some other classes)
  • Open UAMP app
  • Start playing something
  • Pause it
  • Background the app
  • Open the Google Assistant and say: resume
  • The app crashes:
    android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.example.android.uamp.next/com.example.android.uamp.media.MusicService
        at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
        at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
        at android.os.Parcel.readParcelable(Parcel.java:3333)
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2420)
        at android.os.Parcel.createException(Parcel.java:2409)
        at android.os.Parcel.readException(Parcel.java:2392)
        at android.os.Parcel.readException(Parcel.java:2334)
        at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6028)
        at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1855)
        at android.app.ContextImpl.startForegroundService(ContextImpl.java:1831)
        at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:779)
        at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:933)
        at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:701)
        at com.example.android.uamp.media.MusicService$PlayerNotificationListener.onNotificationPosted(MusicService.kt:577)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.startOrUpdateNotification(PlayerNotificationManager.java:1164)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.handleMessage(PlayerNotificationManager.java:1409)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.lambda$ZG0s-7uOzb-YtyUlp8ahx3j4wBg(Unknown Source:0)
        at com.google.android.exoplayer2.ui.-$$Lambda$PlayerNotificationManager$ZG0s-7uOzb-YtyUlp8ahx3j4wBg.handleMessage(Unknown Source:2)

Does the UAMP project still needs to be updated to comply with the latest restrictions around Foreground Services introduced in API 31 ? If this is the case, do you have any idea on when this would happen?

Is it possible that the problem is within the Google Assistant app?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

3reactions
keithburgoynecommented, Jun 29, 2022

Also having this issue on one of our apps. I came here to see how Google solves the problem, only to find … they haven’t.

3reactions
DiegoPinedoEscribanocommented, Jun 14, 2022

It’s a shame that this wasn’t addressed one year ago when Android 12 was introduced. Is Google really unaware of this or are they just ignoring the consequences their bad API decisions have on apps? I really want to know how to solve this problem. I mean, they force developers to target the newest API levels and don’t provide help on how to address such problems.

And btw, I think this doesn’t relate to the Google Assistant because I have seen such crashes on devices where Google services are not available at all. I don’t know how to reproduce it locally, but it’s a fact that this crash happens on production apps.

We have opened an issue on their Issue Tracker in case you wanna also follow that one: https://issuetracker.google.com/u/1/issues/235172948

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Stack Overflow
How to reproduce the crash. Step 1. Update your targetSdkVersion and compileSdkVersion to SDK 31. Step 2. Try to run any Foreground service ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found