Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android exception in MusicBroadcastReceiver - Service Intent must be explicit #42

Closed
jmartine2 opened this issue Oct 28, 2016 · 3 comments

Comments

@jmartine2
Copy link
Contributor

I am recently experiencing a crash due to an exception in MusicBroadcastReceiver, in the second line below:

var stopIntent = new Intent(MediaPlayerService.ActionStop);
context.StartService(stopIntent);

The exception is:

Java.Lang.RuntimeException: Service Intent must be explicit: Intent { act=com.xamarin.action.STOP }

I googled this exception and found the this StackOverflow question about it. I think I get the gist of it's saying, but I'm not sure what exactly to change it to in this instance. Can anyone help?

@jmartine2
Copy link
Contributor Author

Sorry, forgot to mention that this is Android.

@jmartine2 jmartine2 changed the title Exception in MusicBroadcastReceiver - Service Intent must be explicit Android exception in MusicBroadcastReceiver - Service Intent must be explicit Oct 28, 2016
@jmartine2
Copy link
Contributor Author

This issue is still causing me problems. The exception happens in the following circumstance: If I'm playing music through a Bluetooth speaker, then turn off the speaker while the music is playing, the music switches to playing through the device's built-in speaker for a few seconds, then it crashes.

Just before the crash AudioPlayerBroadcastReceiver.OnReceieve() is called, and the call to context.StartService(stopIntent); causes the exception. I have included the stack trace below.

Has anyone else run into this issue?

Any idea of how to fix it?

java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.xamarin.action.STOP }
android.app.ContextImpl.validateServiceIntent()ContextImpl.java:2052
android.app.ContextImpl.startServiceCommon()ContextImpl.java:2090
android.app.ContextImpl.startService()ContextImpl.java:2065
android.content.ContextWrapper.startService()ContextWrapper.java:533
md5cb45d68da0a4a063a9a2b86b6adab38d.AudioPlayerBroadcastReceiver.n_onReceive(Native Method)
md5cb45d68da0a4a063a9a2b86b6adab38d.AudioPlayerBroadcastReceiver.onReceive()AudioPlayerBroadcastReceiver.java:29
android.app.ActivityThread.handleReceiver()ActivityThread.java:3002
android.app.ActivityThread.access$1800()ActivityThread.java:177
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1526
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:145
android.app.ActivityThread.main()ActivityThread.java:5951
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1399
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1194
Xamarin caused by: Java.Lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.xamarin.action.STOP }
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()exceptionservicescommon.cs:143
Java.Interop.JniEnvironment.InstanceMethods.CallObjectMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args)JniEnvironment.g.cs:11283
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualObjectMethod(string encodedMember, IJavaPeerable self, JniArgumentValue* parameters)JniPeerMembers.JniInstanceMethods_Invoke.cs:350
Android.Content.ContextWrapper.StartService(Intent service)Android.Content.ContextWrapper.cs:3281
Plugin.MediaManager.AudioPlayerBroadcastReceiver.OnReceive(Context context, Intent intent)
Android.Content.BroadcastReceiver.n_OnReceive_Landroid_content_Context_Landroid_content_Intent_(IntPtr jnienv, IntPtr native__this, IntPtr native_context, IntPtr native_intent)Android.Content.BroadcastReceiver.cs:393
at (wrapper dynamic-method) System.Object:c3c05af8-86fe-4072-a8b3-4ecfaa76f1eb (intptr,intptr,intptr,intptr)
--- End of managed Java.Lang.IllegalArgumentException stack trace ---
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.xamarin.action.STOP }
android.app.ContextImpl.validateServiceIntent()ContextImpl.java:2052
android.app.ContextImpl.startServiceCommon()ContextImpl.java:2090
android.app.ContextImpl.startService()ContextImpl.java:2065
android.content.ContextWrapper.startService()ContextWrapper.java:533
md5cb45d68da0a4a063a9a2b86b6adab38d.AudioPlayerBroadcastReceiver.n_onReceive(Native Method)
md5cb45d68da0a4a063a9a2b86b6adab38d.AudioPlayerBroadcastReceiver.onReceive()AudioPlayerBroadcastReceiver.java:29
android.app.ActivityThread.handleReceiver()ActivityThread.java:3002
android.app.ActivityThread.access$1800()ActivityThread.java:177
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1526
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:145
android.app.ActivityThread.main()ActivityThread.java:5951
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1399
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1194

@jmartine2
Copy link
Contributor Author

Nevermind. I figured out how to fix it. I will create a pull request for the change soon.

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

No branches or pull requests

2 participants