2

I am trying to make an android app to open files with extension .abc and this is my application section from android manifest xml

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name="com.example.app.ActName" android:label="AppName">
        <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="image/jpeg"/>
        </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:mimeType="*/*" />
            <data android:pathPattern=".*\\.abc" />
            <data android:host="*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

I used all the experience from the most popular and related questions

Android intent filter for a particular file extension?

Android intent filter: associate app with file extension

Android How to create Intent Filter for custom file extension that does NOT make it part of a chooser for everything on the phone

And in the end this does not work - when I click on a file named "name.abc" in ES file browser it asks me if i want to open the file as text or image etc. when it actually supposed to just open the file in my app instead

What am i doing wrong? What is the proper intent filter to launch the app by just clicking a file with the corresponding extension in any file manager?

upd.

it looks like different android systems and different file browsers act in different way - one intent filter works just fine on 4.2 in "ES File Explorer" and on 4.0.4 in default file manager, but does not work at all on 4.2 and 4.0.4 in "Total Commander" and on 4.0.4 in "ES File Explorer"

Community
  • 1
  • 1
Maxim Efimov
  • 2,717
  • 1
  • 16
  • 25

1 Answers1

4

First of all, the first intent-filter in your example uses MIME type image/jpeg. Is jpeg your .abc extension?

I think there may be three reasons why this does not work:

  1. You need to add more MIME types. Try adding the following:

    <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/abc"/>
    </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/octet-stream"/>
    </intent-filter>
    

    And, if your .abc format is a text format:

    <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="text/plain"/>
    </intent-filter>
    
  2. You have registered the file scheme. You might also need the content scheme:

    <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="content" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.abc" />
        <data android:host="*" />
    </intent-filter>
    
  3. Rumor has it that pathPattern with a dot only matches files containing a single dot. In your example, this would mean that your app would be associated with One.abc but not with Two.Dots.abc. Try adding more pathPatterns .*\\..*\\.abc, .*\\..*\\..*\\.abc etc.:

    <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=".*\\..*\\.abc" />
        <data android:host="*" />
    </intent-filter>
    
Community
  • 1
  • 1
Michael Herrmann
  • 3,938
  • 2
  • 29
  • 49
  • 1
    Doesn't seem to work with "files" app of Google: https://play.google.com/store/apps/details?id=com.google.android.apps.nbu.files&hl=en and of Google Drive. Any idea how to support there too? – android developer Jan 12 '19 at 12:01