Reputation: 866
i have two apps which depend on each other and i now want to implement a test on whether all required intents are available.
I have used the general implementation from the Android Developers blog:
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
public static boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); // ADDED BY ME
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
the manifest for the second app (which i check for) contains the following activity:
<activity android:name="MyPackageMyAction" android:exported="true" android:enabled="true">
<intent-filter android:label="License">
<action android:name="com.mypackage.action.myaction"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and i check for it with
boolean available = isIntentAvailable(this, "com.mypackage.action.myaction");
The log output contains this:
VERBOSE/IntentResolver(59): Resolving type null scheme null of intent Intent { act=com.mypackage.action.myaction flg=0x8 }
VERBOSE/IntentResolver(59): Action list: [ActivityIntentInfo{440482c0 com.mypackage.action.myaction}]
VERBOSE/IntentResolver(59): Matching against filter ActivityIntentInfo{440482c0 com.mypackage.action.myaction}
VERBOSE/IntentResolver(59): Filter matched! match=0x108000
VERBOSE/IntentResolver(59): Final result list:
So, i would normally assume that isIntentAvailable returns true if the second app is installed. However, the list returned by queryIntentActivities is always empty.
What am I doing wrong?
Upvotes: 4
Views: 10403
Reputation: 866
Ok, i feel very stupid now. After toying around with this problem for about a day i found the problem.
Everything was registered correctly and should have worked flawlessly, if i weren't so stupid :-). The app receiving the intent is a license key and is supposed to be hidden from the launcher. Therefore i had this line in my app:
pkgMgr.setApplicationEnabledSetting(PACKAGE_NAME, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
After removing it, everything worked straight away. Thanks for all your support!
Upvotes: 1
Reputation: 50578
If you say that this is the only only
activity so the category has to be LAUNCHER
<activity android:name="MyPackageMyAction" android:exported="true" android:enabled="true">
<intent-filter android:label="License">
<action android:name="com.mypackage.action.myaction"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also here you can find more on Intent
http://developer.android.com/reference/android/content/Intent.html#CATEGORY_LAUNCHER
Upvotes: 0