Search code examples
androidintentfilter

Android Open File Associations


I can open custom file extensions when accessing browser links without problem. How can I associate my app with file extensions locally on my device?

Specifically I would like to: 1) Open a file that has been downloaded - I drag the Notifications screen from the top of my display which lists recent .xm files that have been downloaded. I would like to be able to tap on those and have my application open these files.

2) Likewise with other file explorer apps if possible.

Here are my intent filters. What am I missing?

    <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" />
        <data android:scheme="file" />
        <data android:pathPattern=".*\\.xm" />
        <data android:host="*" />
        <data android:mimeType="text/plain"/>
    </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" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.xm" />
        <data android:host="*" />
    </intent-filter> 

UPDATE: See below filters

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.EDIT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:mimeType="application/octet-stream"
            android:host="*" 
            android:pathPattern=".*\\.xm"
        />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.EDIT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:mimeType="application/mytype"
            android:host="*" 
            android:pathPattern=".*\\.xm"
        />

Solution

  • This post has helped me solved the problem. I'm including the required intent filters above in the original question.