Search code examples
androidintentfilter

Unable to open 2nd app using Custom Intent Action in Android


I have written one application which handles some specific intent filters, here is the manifest of the application:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.sampleapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name="com.company.sampleapp.MainActivity"
            android:enabled="true"
            android:exported="true"
            android:label="@string/app_name" >

            <!-- 1 filter -->
            <intent-filter>
                <action android:name="com.company.sampleapp.ACTION_DO_SOMETHING_1" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <!-- 2 filter -->
            <intent-filter>
                <action android:name="com.company.sampleapp.ACTION_DO_SOMETHING_2" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <!-- default filter -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.company.sampleapp.Seconf=dActivity"
            />
    </application>
</manifest>

I am calling this application from a second application using following code:

Intent i = new Intent("com.company.sampleapp.ACTION_DO_SOMETHING_1");
startActivityForResult(i, 100);

i have also tried:

Intent i = new Intent();
i.setAction("com.company.sampleapp.ACTION_DO_SOMETHING_1");
startActivityForResult(i, 100);

But everytime,i am getting following exception:

07-18 14:22:56.234: E/AndroidRuntime(12051): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.company.sampleapp.ACTION_DO_SOMETHING_1 }

Please help.


Solution

  • I think you are missing <data android:mimeType="..."/> into <intent-filter>.

    Try with

    <intent-filter>
      <action android:name="com.company.sampleapp.ACTION_DO_SOMETHING_1" />
      <data android:mimeType="*/*"/>
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    

    Read more about Allowing Other Apps to Start Your Activity