No Activity found to handle Intent (API Level 19)

811 views Asked by At

For the life of me, I have been battling with this implicit intent for over 2 days now. I am trying to start an Activity implicitly using startActivity(intent) but I keep getting the "No activity found to handle intent", I have followed the directions on the android developer site on how to create and handle implicit intents and have scoured the web including a lot of posts on stackoverflow but the issue persists. Now time for some code:

Component A - Fires the implicit intent

Intent intent = new Intent();
//intent.setFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
intent.setAction(AppConstants.ACTION_VIEW_OUTLET);
//intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.withAppendedPath(OutletsContentProvider.CONTENT_URI,String.valueOf(outletID)));
intent.addCategory(Intent.CATEGORY_DEFAULT); 

    PackageManager pm = getPackageManager();
    ComponentName cn = intent.resolveActivity(pm);

    if(cn != null){
        startActivity(intent);
        Log.i(TAG, "Intent sent with action :" + intent.getAction());
        Log.i(TAG, "Intent sent with data :" + intent.getDataString());
    }

Android Manifest (within the same app as component A)

    <activity
        android:name=".OutletDetailsActivity"
        android:label="@string/title_activity_outlet_details">
        <intent-filter>
            <data android:scheme="content" />
            <action android:name="com.synkron.pushforshawarma.ACTION_VIEW_OUTLET" />

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

What could I be doing wrong? I have had a huge success using broadcast intents, but I don't want to use a broadcast/receiver in this case.

1

There are 1 answers

0
Oladipo Olasemo On BEST ANSWER

So I finally figured it out.

It just so happens that when data (URI, either by setData or by using the constructor that accepts the URI) is set on an intent, the system determines the appropriate MIME type required by the intent.

    Intent intent = new Intent(AppConstants.ACTION_VIEW_OUTLET);
    intent.putExtra("OUTLET_ID", 
        Uri.withAppendedPath(OutletsContentProvider.CONTENT_URI, String.valueOf(outletID)));
    intent.addCategory(Intent.CATEGORY_DEFAULT); 

When a URI or data is not set or specified, one is required to use settype() to specify the type of data (MIME) associated with the intent.

So basically, I didn't set the MIME type (I am required to since I set data (URI)) while initializing my intent. The intent-filter could not match the implicit intent because the data type test failed.

My work around, I passed my URI via the putExtra method leaving the data unset.

I also removed the reference to the data tag in the intent filter from the android manifest.

    <activity
        android:name=".OutletDetailsActivity"
        android:label="@string/title_activity_outlet_details">
        <intent-filter>
            <action android:name="com.synkron.pushforshawarma.ACTION_VIEW_OUTLET" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>