Although I saw several threads and tutorials on this topic, I guess that I still have confusion about how the application can be selected from the list of applications to display the file.
I have an Activity in which there is a list view. This list view is associated with file paths (so the file browser is sorted). When we click on a specific type of file, I need a list of applications that can open this file.
So far, this is what I have in 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 (downloadable from the market), I have two options (QuickOffice and Word to Go), both of which I installed on my phone.
- , ? , , :
:
<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>
:
myIntent.setDataAndType(Uri.fromFile(new File(filePath)),"*");
.
!