开发者

integrating amazon mp3 in my android application

in my android application i want to add the functionality the user to buy song from amazon. The easiest way to do is i think to use amazon mp3 application to communicate with amazon store. I found this piece of code from default music player

Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
i.putExtra(SearchManager.QUERY, mSong.getArtits() + " " + mSong.getName());
i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, "artist");
i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, "album");
i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, mSong.getName());
i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
startActivity(Intent.createChooser(i, "Search for " + mSong.getName()));

which shows menu to select where to search for your song (browser, youtube, amazon mp3). But here are some things i want to do -

  1. I don't want to show the whole pop up screen but only amazon search, what intent i should us开发者_如何学JAVAe to search directly in amazon mp3.
  2. How can i send my affiliate partner key to amazon mp3 so it can included it when querying amazon.

Shazam is using directly amazon mp3 but i couldn't find any information what intent i should use. Thanks in advance any help will be very helpful.


It's not a public API; Shazam apparently have a private arrangement with Amazon. It might be worth contacting Amazon directly, since they have a lot of public APIs, and this one would certainly seem to be in their interests. But like any large company, I wouldn't hold your breath for a response.


as for 1., you can try to determine the correct activity by evaulating the list of matching activities like this (i being the intent you created):

List<ResolveInfo> info = getPackageManager().queryIntentActivities(i, 0);
String packageName=null, className=null;
for ( ResolveInfo r: info){
    if ( r.activityInfo.packageName.startsWith("com.amazon.mp3")){
        packageName=r.activityInfo.packageName;
        className=r.activityInfo.name;
        break;
    }
}
if ( packageName != null && className != null)
    i.setClassName(packageName, className);
startActivity(i);

This is sort of a hack since one should not rely on the package name starting with a certain fixed string, but in fact it will probably work for long. Just be prepared in your code to deal with it changing (android will automatically display the activity chooser if the Amazon activity is not identified).

as for 2., sorry, I have no information about this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜