0
votes

I have tried different things but unsure what is going wrong, I get this error when I start this specific service.

Service intent must be explicit: Intent { act=com.xamarin.action.PLAY(has extras) }

I am passing a string ID when starting the service as following

var intent = new Intent(MediaService.ActionPlay);
intent.PutExtra("ID", ID);                                
StartService(intent); // Error here

My service looks something like the following

[Service]
[IntentFilter(new[] { ActionPlay, ActionPause, ActionStop })]
public class MediaService: Service
  {
   public const string ActionPlay = "com.xamarin.action.PLAY";
   public const string ActionPause = "com.xamarin.action.PAUSE";
   public const string ActionStop = "com.xamarin.action.STOP";

   public override StartCommandResult OnStartCommand(Intent intent, 
     StartCommandFlags flags, int startId)
     { 
       switch (intent.Action)
                {
                    case ActionPlay: Play(intent.GetStringExtra("ID")); break;
                    case ActionStop: Stop(); break;
                    case ActionPause: Pause(); break;
                }
     }     
  }

Where the play action is the following

public bool Play(string playID)
{ 
   ....
}

What am i doing wrong.

1

1 Answers

1
votes

You can set the package id of your intent:

intent.SetPackage(PackageName);

Or use the current context and the Java class (or C# type):

var intent = new Intent(Application.Context, typeof(MediaService));