Thursday, 3 September 2015

android open another app by intent

A app will open B app

the code of A app for open B app

Intent emailIntent = new Intent("com.marksandspencer.guardianangel.main");
//emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {""}); 
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(emailIntent, 0);
boolean isIntentSafe = activities.size() > 0;

if (isIntentSafe) {

this is the AndroidManifest.xml file of B app:

    android:label="@string/app_name" >
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />

        <action android:name="com.marksandspencer.guardianangel.main"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <!--<data android:mimeType="text/plain" />-->



If B app need a text input, you should open all Green highlighted codes.

If B app doesn't need a text input, you should not open both Green highlighted codes above, otherwise the system will think this is a different intent.

If not intent matches, you will see no error and logs.

No comments:

Post a comment