Search code examples
androiddefaultaudio-playerandroid-music-player

Set my app as default music player in android programatically


When we click a mp3 file we get the popup window showing default apps which can play that file.

How can I add my app to that list?

For developing the app I referred a tutorial on tuts+.

I am using a service called player service referring to a android-developers blog post.

I have added following code to the <service> definition in the manifest file

<intent-filter>
    <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>

What mime type should I set to make my app as one of the default apps?

I am not able to see my app in the popup window.


Solution

  • It's not possible to set your app as default music player programmatically. It has to be done by the user when it's shown in the popup window you're referring to.

    To get your app there you could refer to the manifest of the (outdated) android music player

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="content"/>
        <data android:host="media"/>
        <data android:mimeType="audio/*"/>
        <data android:mimeType="application/ogg"/>
        <data android:mimeType="application/x-ogg"/>
        <data android:mimeType="application/itunes"/>
    </intent-filter>
    

    The main item you need from there is the <action> element. See intent filter without action for more details to the issues here. The additional <data> elements might come in handy for a wider range of locations to support.