How do I make an intent-filter for playing an MP3

2019-01-29 00:36发布

问题:

I have created a music player application in Android. Now, when selecting a music file in the phone's file manager, I want my application to appear as one of the options in the "Complete action using" popup. My idea is to do this using intent filter but I have no idea what action, category, or data I need to supply to it. How do I create an intent filter for this?

I've also seen a related question here: How do I make an intent-filter for streaming an MP3 file? but mine is not streaming, i am just playing music from file.

Thank you in advance.

回答1:

Hope this Intent Filter can help you

<intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="content"/>
        <data android:scheme="file"/>
        <data android:mimeType="audio/*"/>
    </intent-filter>


回答2:

Hope this Intent filter can help you

        <activity android:name="AudioPlayerActivity">
             <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:scheme="content" />
            <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>
      <activity/>