Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is no Activity found to handle Intent?

Instead of going the regular getPackageManager().getLaunchIntentForPackage("com.example.app") way, I want to create the launch intent by myself.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage("com.example.app");
startActivity(intent);

Why does Android not find the Activity, if the com.example.app is installed, enabled and has a correct manifest? (It works perfectly with getLaunchIntentForPackage.)

like image 466
Tamás Bolvári Avatar asked Feb 02 '19 11:02

Tamás Bolvári


People also ask

How do I get activity in intent?

1.2. To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.

Could not open URL no activity found to handle intent?

You see no activity found to handle intent when you attempt to launch an intent either to open a link or to access an app component. It's an error message that is caused because the device is not an official android, Google Play is not supported, or it's a rooted device.

What is the intent of an activity?

An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity() . The Intent describes the activity to start and carries any necessary data.

What is intent activity in Android?

An intent is to perform an action on the screen. 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. Here is a sample example to start new activity with old activity.


2 Answers

I understand that you are trying to start the Launcher activity of a known application with known package name (com.example.app). I assume you have information about the application. Thus, you can start it via explicit intent like so:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example.app", "com.example.app.MainActivity"));
if(intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

EDIT: Doing an analysis of the two intent objects (intent1 == your own intent VS intent2 == intent created from getLaunchIntentForPackage()), the difference is

intent1:

{ act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=com.example.app }

intent2:

{ act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.example.app cmp=com.example.app/.MainActivity }

I will have to believe that what you have done to create your own intent object is not enough for the explicit intent to work. You will have to provide Android more information about your intent such as being specific with the component name (as shown in my answer above).

like image 196
user1506104 Avatar answered Oct 06 '22 10:10

user1506104


'To receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter.' - Does your receiving app have this?

Example:

<activity android:name="ShareActivity">
     <intent-filter>
         <action android:name="android.intent.action.SEND"/>
         <category android:name="android.intent.category.DEFAULT"/>
         <data android:mimeType="text/plain"/>
     </intent-filter>
</activity>

Excerpt from: https://developer.android.com/guide/components/intents-filters#Receiving

You can also check to make sure there is an activity that can receive your broadcast:

 PackageManager packageManager = getPackageManager();
 List<ResolveInfo> activities = packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
 boolean isIntentSafe = activities.size() > 0;

Excerpt from: https://developer.android.com/training/basics/intents/sending#java

like image 29
AzraelPwnz Avatar answered Oct 06 '22 12:10

AzraelPwnz