Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associating certain file extension to my android application

I'm having trouble associating my custom file extension to my android application that I am developing. In my android manifest file I have the following:

<data android:scheme="file" android:mimeType="*/*" android:pathPattern="*.*\\.myFileExt" />
<data android:scheme="content" android:mimeType="*/*" android:pathPattern="*.*\\.myFileExt" />  

It kinda works. Let me explain. I have a file in my gmail( sent a file to my self ), which has the proper extension, so when I download it from my phone's browser and click open, it opens my application correctly, but if I explore to that file path; where the file is located, and try to open it, my phone says no application can open this file-type.

Any ideas on how to solve this problem?

like image 558
dchhetri Avatar asked Aug 11 '11 18:08

dchhetri


2 Answers

After spending a few hours on this issue I finally came up with this solution (AAA is the file extension):

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
    <data android:scheme="file" />
    <data android:host="*" />
    <data android:port="*" />
    <data android:pathPattern=".*..*..*..*..*.AAA" />
    <data android:pathPattern=".*..*..*..*.AAA" />
    <data android:pathPattern=".*..*..*.AAA" />
    <data android:pathPattern=".*..*.AAA" />
    <data android:pathPattern=".*.AAA" />
</intent-filter>

The reason for all of those pathPattern is that if you have a dot in your file name the general form of .*.AAA will not match the filename.

like image 60
Muzikant Avatar answered Nov 13 '22 02:11

Muzikant


Some cases are kinda tricky, I've settled on using:

    <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=".*\\.myFileExt" />
        <data android:host="*" />
    </intent-filter>

and this sometimes fails because sometimes only a more global mime type (in my case XML) is used:

    <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/xml" />
    </intent-filter>
like image 35
Rene Avatar answered Nov 13 '22 00:11

Rene