I am getting this crash on my crashlytics,have anyone faced an issue like this?
Thx,in advance
Exception java.lang.RuntimeException: Unable to start receiver android.support.v4.media.session.MediaButtonReceiver: java.lang.IllegalStateException: Could not find any Service that handles [REDACTED_DOMAIN_NAME]_BUTTON or a media browser service implementation android.app.ActivityThread.handleReceiver (ActivityThread.java:3643) android.app.ActivityThread.access$2000 (ActivityThread.java:222) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1878) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:158) android.app.ActivityThread.main (ActivityThread.java:7230) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230) com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:1120) Caused by java.lang.IllegalStateException: Could not find any Service that handles [REDACTED_DOMAIN_NAME]_BUTTON or a media browser service implementation android.support.v4.media.session.MediaButtonReceiver.onReceive (MediaButtonReceiver.java:97) android.app.ActivityThread.handleReceiver (ActivityThread.java:3636) android.app.ActivityThread.access$2000 (ActivityThread.java:222) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1878) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:158) android.app.ActivityThread.main (ActivityThread.java:7230) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
if you update your project with androidX dependencies, you must import
<receiver android:name="androidx.media.session.MediaButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON"/>
</intent-filter>
</receiver>
Google official document's explain: This class assumes you have a Service in your app that controls media playback via a MediaSessionCompat. Once a key event is received by MediaButtonReceiver, this class tries to find a Service that can handle Intent.ACTION_MEDIA_BUTTON, and a MediaBrowserServiceCompat in turn. If an appropriate service is found, this class forwards the key event to the service. If neither is available or more than one valid service/media browser service is found, an IllegalStateException will be thrown. Thus, your app should have one of the following services to get a key event properly.
You can solve it in the following ways:
1.A service can receive a key event by including an intent filter that handles Intent.ACTION_MEDIA_BUTTON:
<service android:name="com.example.android.MediaPlaybackService" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</service>
Events can then be handled in Service.onStartCommand(Intent, int, int) by calling handleIntent(MediaSessionCompat, Intent), passing in your current MediaSessionCompat:
private MediaSessionCompat mMediaSessionCompat = ...;
public int onStartCommand(Intent intent, int flags, int startId) {
MediaButtonReceiver.handleIntent(mMediaSessionCompat, intent);
return super.onStartCommand(intent, flags, startId);
}
This ensures that the correct callbacks to MediaSessionCompat.Callback will be triggered based on the incoming KeyEvent.
2.MediaBrowserService
If you already have a MediaBrowserServiceCompat in your app, MediaButtonReceiver will deliver the received key events to the MediaBrowserServiceCompat by default. You can handle them in your MediaSessionCompat.Callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With