2

My app specifies as being able to open my own file extension in the manifest file like this:

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.ext" />
<data android:pathPattern=".*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.ext" />

This used to work fine with the standard Android file browser ("My Files") and still works on an older test device running Android 4.3 but doesn't work on my other devices running Android 6 and 8. It also works on the new devices with other file browsers (though not all).

I also tried png and pdf with the corresponding mime types but it won't show my app in the list of apps able to open those files.

What does the standard Android file browser need in order to recognize my app to be able to open files with my extension?

EDIT: I also tried

<data android:scheme="content"/>
erinys
  • 273
  • 1
  • 4
  • 18
  • some device will use content mime type instead of file. To fix issue, you have to detect witch intent is launched for resolution. From Android file browser, choose option open with, you will get the log for intent... as this one for pdf file... 2018-11-02 00:46:51.515 1714-8164/system_process I/ActivityManager: START u0 {act=android.intent.action.CHOOSER flg=0x3 cmp=android/com.android.internal.app.ChooserActivity clip={application/pdf U:content://com.android.providers.downloads.documents/document/55} (has extras)} from uid 10012 – Anis BEN NSIR Nov 01 '18 at 23:53
  • Thanks for that but unfortunately, myfiles doesn't give me any log like that. No indication that it tried to call an intent. The only logs that I can see from myfiles are about drawing the activity. I have also tried setting the scheme as content, same result. – erinys Nov 02 '18 at 06:09
  • Opening a jpg from My Files gives me this line: W/ResolverActivity: mLaunchedFromPackage = com.sec.android.app.myfiles and I/ActivityManager: START u0 {act=android.intent.action.VIEW typ=image/jpeg flg=0x1 cmp=ComponentInfo{android/com.android.internal.app.ResolverActivity}} from uid and shows a chooser for two apps capable of opening jpg files. Neither of these logs happen for files with my own extension. – erinys Nov 02 '18 at 06:14
  • when you want to open your file, witch application can handle it? – Anis BEN NSIR Nov 02 '18 at 14:55
  • My own application can handle the files. I want my own application, where the above intent-filter is specified, to open when the file is clicked in "myfiles". – erinys Nov 02 '18 at 19:30

1 Answers1

0

Try this (change "custom" with the extension you want to use) :

   <activity android:name=".MainActivity">
        <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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.custom"/>
            <!-- These additional pathPattern blocks are to allow for paths with
            additional periods in them. See:
            http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i/8599921 -->
            <data android:pathPattern=".*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
            <data android:host="*"/>
        </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="file"/>
            <data android:pathPattern=".*\\.custom"/>
            <data android:pathPattern=".*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
            <data android:host="*"/>
        </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:mimeType="application/vnd.ni.custom" android:scheme="file"/>
        </intent-filter>
    </activity>
android developer
  • 114,585
  • 152
  • 739
  • 1,270