Search code examples
androidaudioandroid-manifestintentfilterfile-association

register as music player


I'd like to see my app in the list of player ("continue action using...") that pops up when I try to open an audio file (ie. from file browser or gmail attachment). Here are the intent filters I've tried for my MainActivity:

    <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.SEARCH" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.MUSIC_PLAYER" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.CATEGORY_APP_MUSIC" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:mimeType="audio/mpeg" />
    </intent-filter>

thanks for your help !


Solution

  • You always need a <category> on an <activity> <intent-filter>, as there is always at least one category on the Intent used with startActivity().

    Here is what the AOSP Music app uses:

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file"/>
                <data android:mimeType="audio/*"/>
                <data android:mimeType="application/ogg"/>
                <data android:mimeType="application/x-ogg"/>
                <data android:mimeType="application/itunes"/>
            </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="audio/*"/>
                <data android:mimeType="application/ogg"/>
                <data android:mimeType="application/x-ogg"/>
                <data android:mimeType="application/itunes"/>
            </intent-filter>
            <intent-filter
                android:priority="-1">
                <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="audio/*"/>
                <data android:mimeType="application/ogg"/>
                <data android:mimeType="application/x-ogg"/>
                <data android:mimeType="application/itunes"/>
            </intent-filter>