Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get implicit intents to work

I'm learning how to use implicit intents along with intent filters, and have so far been unable to get the correct activity to fire. The code that is used to fire the intent is:

intent = new Intent();
intent.setAction("com.appsculture.intent.action.PLUGIN_RECEIVER");
startActivity(intent);

And the Intent filter for the desired activity is:

<activity android:name="PluginReceiver">
<intent-filter>
    <action android:name="com.appsculture.intent.action.PLUGIN_RECEIVER"></action>
</intent-filter>
</activity>

The error I get is the standard ActivityNotFound

09-04 17:15:27.827: ERROR/AndroidRuntime(2552): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.appsculture.intent.action.PLUGIN_RECEIVER }

Solution: Simply addeded the android.intent.category.DEFAULT category to the intent filter

Works like a charm after that

like image 468
Raveesh Bhalla Avatar asked Sep 04 '11 11:09

Raveesh Bhalla


People also ask

How do you start an activity using implicit intent?

For this, Open the MainActivity file and instantiate the component (Button) created in the XML file using the findViewById() method. This method binds the created object to the UI Components with the help of the assigned ID.

How do you call implicit intent?

Implicit Intent with URI data Uri number = Uri. parse("tel:11061991"); Intent callIntent = new Intent(Intent. ACTION_DIAL, number);

What is not specified by implicit intent?

Implicit Intents do not directly specify the Android components which should be called, it only specifies action to be performed. A Uri can be used with the implicit intent to specify the data type. Intent intent = new Intent(ACTION_VIEW,Uri.

What is implicit intent in android example?

For example, you might start a new activity within your app in response to a user action, or start a service to download a file in the background. 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.


2 Answers

I managed to solve this by simply adding the android.intent.category.DEFAULT category to the intent filter. Works like a charm after that.

As Commonsware has indicated in a comment on his answer, a category is required for Activities, though not for services or broadcast receivers.

like image 181
Raveesh Bhalla Avatar answered Sep 19 '22 13:09

Raveesh Bhalla


Everything you have there should be fine, though I'd use new Intent("com.appsculture.intent.action.PLUGIN_RECEIVER"), and the use of RECEIVER seems like an odd piece of an action name for an Activity instead of a BroadcastReceiver.

If these are in two separate applications, make sure both are installed on your device or emulator, with the latest code (i.e., you didn't make the change and then fail to install the updated app).

like image 41
CommonsWare Avatar answered Sep 21 '22 13:09

CommonsWare