tanguyantoine / react-native-music-control

Display and manage media controls on lock screen and notification center for iOS and Android.
https://www.npmjs.com/package/react-native-music-control
MIT License
697 stars 264 forks source link

ForegroundServiceStartNotAllowedException on Android SDK 31+ #405

Closed elliotdickison closed 2 years ago

elliotdickison commented 2 years ago

Problem

Compiling an Android app with targetSdkVersion >= 31 results in the attached fatal when react-native-music-control attempts to start a foreground service from the background here.

Attempted fix

An attempt to fix this was made in GH-402 by adding android:foregroundServiceType="mediaPlayback" to the service declaration (released in 1.4.1), but unfortunately this did not fix the issue.

Other info

Description

  1. Sample code (provide repo url or sample code)
android.app.ForegroundServiceStartNotAllowedException: 
  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:3345)
  at android.os.Parcel.createExceptionOrNull (Parcel.java:2432)
  at android.os.Parcel.createException (Parcel.java:2421)
  at android.os.Parcel.readException (Parcel.java:2404)
  at android.os.Parcel.readException (Parcel.java:2346)
  at android.app.IActivityManager$Stub$Proxy.startService (IActivityManager.java:6965)
  at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1926)
  at android.app.ContextImpl.startForegroundService (ContextImpl.java:1892)
  at android.content.ContextWrapper.startForegroundService (ContextWrapper.java:796)
  at androidx.core.content.ContextCompat$Api26Impl.startForegroundService (ContextCompat.java:933)
  at androidx.core.content.ContextCompat.startForegroundService (ContextCompat.java:701)
  at com.tanguyantoine.react.MusicControlNotification$NotificationService.forceForeground (MusicControlNotification.java:215)
  at com.tanguyantoine.react.MusicControlModule$1.onServiceConnected (MusicControlModule.java:243)
  at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2235)
  at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2268)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8669)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)
  1. Platform ?

    • [ ] iOS
    • [x] Android
  2. Device

    • [ ] Simulator
    • [x] Real device
elliotdickison commented 2 years ago

Duplicate of #400