0

I have a custom file type with the extension .myext. I've read android doc and many SO posts to understand how to configure intent filter to associate these files to my app. It works but not properly.

When I use this 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/*" />
            <data android:pathPattern=".*\\.myext" />
            <data android:host="*" />
        </intent-filter>

then it links .myext files to my app, but also every file that has no app assoiated. So I can open .otherext file which I don't want.

Then I found this answer https://stackoverflow.com/a/5097734/575481 which suggest to have multiple intent-filter, So I get :

        <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="http" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.myext" />
        </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="http" />
            <data android:host="*" />
            <data android:mimeType="application/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.myext" />
        </intent-filter>

but this doesn't seem to work for me.

What I want is that : my apps opens only .myext files. Do you have any idea ?

Furthermore I will need to open some other file ext (.myext1, .myext2) , but I guess once I get the proper intent-filter, I just have to duplicate it for the others with the extension, right ?

Community
  • 1
  • 1
Vincent
  • 973
  • 12
  • 33

1 Answers1

1

I got it. In my case I am trying to get a .ppp from e-mail and it was fetching any file. this is the working 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="content"   android:pathPattern=".*\\.ppp" android:mimeType="application/ppp"/>
        </intent-filter>

on your activity's onCreate put a breakpoint and check the values in

    getIntent()

specifically mData should give you what to write for the android:scheme and mType what to write for the android.mimeType

sudavid4
  • 883
  • 5
  • 12