Tigran
Tigran

Reputation: 1057

Android request to another service - explicit vs implicit intent

I am trying to make a request to another service (another app), but getting exception:

java.lang.IllegalArgumentException: 
Service Intent must be explicit: Intent { act=com.myApp.DoAction }

I did some readings and still confused:
Here, it's written: Since Android 5.0 (Lollipop) bindService() must always be called with an explicit intent.
Here, it's written: Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it

What will be the right intent? What will be the right example? I am doing:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setAction("com.anotherApp.MyService");
// binding to remote service
bindService(intent, AddServiceConnection, Service.BIND_AUTO_CREATE);

Many many thanks for help.

Upvotes: 0

Views: 247

Answers (2)

Tigran
Tigran

Reputation: 1057

After trying some tutorials: Intent is implicit and this nice example shows how to deal with it

Intent intent = new Intent("com.anotherapp.MyService");
intent.setPackage("com.anotherapp");
bindService(intent, AddServiceConnection, Service.BIND_AUTO_CREATE);

Upvotes: 0

Revaz Shalikashvili
Revaz Shalikashvili

Reputation: 143

I believe that this Intent intent = new Intent(Intent.ACTION_SEND);

line of code says that intent action is implicit. It declares intent with abstract SEND action. try removing Intent.ACTION_SEND

Upvotes: 1

Related Questions