user422168
user422168

Reputation: 31

Android Launching an application chooser with appropriate list of applications

Although I have seen several threads and tutorials on this topic, I guess I still have some confusion on how an application can be chosen from a list of applications to display a file.

I have a Activity which has a list view in it. This list view is bound with file paths (so a file browser of sorts). When we click on a specific file type, I need a list of applications that can open that file.

So far this is what I have in the OnItemClick for the list item:

Intent myIntent = new Intent();
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.addCategory("android.intent.category.DEFAULT");
myIntent.setData(Uri.fromFile(new File(filePath)));

When I run this on my phone, the error is: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] dat=file:///

When I do the same in a file browser application (downloaded from the marketplace), I get two options (QuickOffice and Word to Go), both of which I have installed on my phone.

Could someone guide me as to what else is needed here? Things I have tried besides the above:

  1. Add the following entries to the manifest:

    <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" > <category android:name="android.intent.category.DEFAULT" > <data android:scheme="file" /> </intent-filter>

  2. Explicitly set the type:

    myIntent.setDataAndType(Uri.fromFile(new File(filePath)),"*");

Neither of this works, any help is appreciated.

Thanks!

Upvotes: 3

Views: 3538

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006664

First, * is not a MIME type. You have to use setDataAndType() and supply the real MIME type. If you do not know the real MIME type, you cannot build your application.

Second, I would get rid of the addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) and addCategory("android.intent.category.DEFAULT") unless you have absolute proof that you need them.

Third, the intent filters on your activity have nothing to do with the intent filters of any other activity, and so all those filters you tried in #1 will not matter and probably should be removed.

Upvotes: 1

Related Questions