问题
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