views:

568

answers:

1

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/.SearchListActivity (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?

+2  A: 

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);
    ...
}
David Hedlund
Hi David,Thanks for the tip. But EXTRA_MEDIA_TITLE is coming null. I tested on my device (1.5) and Emulator (2.1). However; the other extras are coming fine. Did you have a chance to get the Title?
Omer
@Omer: Hi. Whether or not `EXTRA_MEDIA_TITLE` has a value depends on how you perform the search (and I guess on how media search is implemented in your music player). in the stock 2.1 player, if you long-click on the album name, you'll search for that album, if you long-click on the title, you'll search for the title. In the former case, `TITLE` will be null. You can also check `MediaStore.EXTRA_MEDIA_FOCUS` to find out what was searched for.
David Hedlund