I have written the below intent filter to open a text file using my app. It seems to work but only sometimes. For example, if I email a text file, if I choose open from mail, my app is not shown. If I choose save first, then open, my app will be shown. Similar experience with drop box, if I try to open from drop box, my app won’t be listed as being able to open but if I export from drop box to sd and use a file manager to open it, my app is listed and works.
<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.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.txt" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.txt" />
<!-- <data android:scheme="content" android:host="*" android:pathPattern=".*\\.txt" /> -->
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.txt" />
</intent-filter>
Dropbox and the Email app probably use content providers and don’t match the
pathPattern. Typically content providers don’t include a file extension, but would use the mime type to indicate what type of file is being opened. If you are intending to open anytext/plainfile, and not necessarily only those which have the.txtextension, then you’d be better off leaving thepathPatternoff altogether.