Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Intent must be explicit: Intent

I have an app some time now in which I call a service through a broadcast receiver (MyStartupIntentReceiver). The code in the broadcast receiver in order to call the service is:

public void onReceive(Context context, Intent intent) {     Intent serviceIntent = new Intent();     serviceIntent.setAction("com.duk3r.eortologio2.MyService");     context.startService(serviceIntent); } 

The problem is that in Android 5.0 Lollipop I get the following error (in previous versions of Android, everything works ok):

Unable to start receiver com.duk3r.eortologio2.MyStartupIntentReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.duk3r.eortologio2.MyService } 

What do I have to change in order for the service to be declared as explicit and start normally? Tried some answers in other similar threads but although i got rid of the message, the service wouldn't start.

like image 891
duk3r Avatar asked Jan 08 '15 14:01

duk3r


People also ask

What is intent implicit?

An implicit intent specifies an action that can invoke any app on the device able to perform the action. Using an implicit intent is useful when your app cannot perform the action, but other apps probably can and you'd like the user to pick which app to use.

What is intent explain types of intent with example?

Intent is to perform an action. It is mostly used to start activity, send broadcast receiver, start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents. Intent send = new Intent(MainActivity.

What is intent filter verification service?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.” – developer.android.com.


2 Answers

any intent you make to a service, activity etc. in your app should always follow this format

Intent serviceIntent = new Intent(context,MyService.class); context.startService(serviceIntent); 

or

Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND"); bi.setPackage("com.android.vending"); 

implicit intents (what you have in your code currently) are considered a security risk

like image 116
tyczj Avatar answered Sep 23 '22 18:09

tyczj


Set your packageName works.

intent.setPackage(this.getPackageName()); 
like image 31
kai chen Avatar answered Sep 19 '22 18:09

kai chen