开发者

Android native music player search intent

In the stock music player in Android 2.1 (at least), the artist, album, and track name of the currently playing track are long clickable, which brings up a context menu "Search for NN with:", with links to different apps.

UPDATE

I've managed to extract the logs from my own device, doing a search for an artist, and selecting Google Listen to complete the action:

03-02 11:59:34.551 I/ActivityManager(   86): Displayed activity com.android.music/.MediaPlaybackActivity: 1758 ms (total 1953 ms)
03-02 11:59:35.691 I/ActivityManager(   86): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
03-02 11:59:36.781 I/ActivityManager(   86): Displayed activity android/com.android.internal.app.ChooserActivity: 1036 ms (total 1036 ms)
03-02 11:59:38.191 I/ActivityManager(   86): Starting activity: Intent { act=android.intent.action.MEDIA_SEARCH flg=0x13000000 cmp=com.google.android.apps.listen/.SearchListActi开发者_如何学运维vity (has extras) }
03-02 11:59:38.511 D/Listen  (  491): Request search results for http://lfe-alpo-gm.appspot.com/search?q=Finntroll

I will definitely pursue this myself, but this is quite new to me. I'd appreciate assistance here. Does the above mean that as long as I set up MEDIA_SEARCH intent as an entry point for an activity, it'll show up in the select list?


Alright, MEDIA_SEARCH was the right way to go. For reference:

Adding the intent filter is enough to make the application show up in the select list in the media player:

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

And then the action can be received as follows:

final Intent queryIntent = getIntent();
final String queryAction = queryIntent.getAction();

if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(queryAction)) {
    String artist = queryIntent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
    ...
}
  • INTENT_ACTION_MEDIA_SEARCH
  • EXTRA_MEDIA_ARTIST
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜