How do I make an intent-filter for streaming an MP3 file?

一曲冷凌霜 提交于 2020-01-01 05:44:05

问题


On Android, if you type a URL to an MP3 file in the browser (or click on a link to the file) you get that "Complete action using" popup with some applications listed that can play the file (Music, StreamFurious, Streaming Media Player, Winamp, XiiaLive Lite, to name a few). How can I get my application to show up in that list?

I'm pretty sure there's an intent-filter I have to add to the AndroidManifest.xml but I have no idea what action, category, or data needs to be in it. Anyone know what I have to do? Also, is there some way I can trace intents that called on the system? That might make it easier to figure out how to do other things like this in the future.

Based on what I saw at code.google.com/p/andless/source/browse/trunk/AndroidManifest.xml?spec=svn86&r=86# I tried this:

<activity android:name=".Main"
          android:label="@string/app_name">
    <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:mimeType="audio/mp3" android:scheme="file" />
    </intent-filter>
</activity>

but that didn't do it. Then I downloaded andLess from the market and realized that app doesn't show in the "Complete action using" list either.


回答1:


You might want to add this filter:

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

By the way, don't forget the necessary permissions...that's important.^^

oh yeah...i totally forgot to mention you need receivers. in case you dont know that yet. broadcast receivers..like this

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

what basically happens here is, when a file is launched/clicked maybe from a file browser, android broadcasts and sells the file to possible applications that may be interested with the kind of file. therefore, we need to establish which files our applications will/may respond to. and that's through broadcast receivers. but you probably know that already. i hope this helped..sorry for the delay i was afk.

i am editting this again...you need this inside your application tag. ^^




回答2:


No receiver needed. This works. When you click the link it tries to "view" the contents of the link so the intent-filter needs the view action and browsable category. And the correct data settings are listed below:

<activity android:name=".Main"
          android:label="@string/app_name">
    <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" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:pathPattern=".*mp3" android:mimeType="audio/*" />
    </intent-filter>
</activity>


来源:https://stackoverflow.com/questions/6824192/how-do-i-make-an-intent-filter-for-streaming-an-mp3-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!