安卓:通过启动服务音乐播放器 [英] Android : Launch Music Player via Service
本文介绍了安卓:通过启动服务音乐播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从服务启动的MediaPlayer,并预期它不是wroking。我m到处以下异常,
I am trying to launch the MediaPlayer from a service, and its not wroking as expected. I m getting the following exception,
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MUSIC_PLAYER flg=0x10000000 }
请找到获取在服务调用code的片断,
Please find the snippet of code that gets invoked in the service,
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Android清单
Android Manifest
<service android:name="com.lakshmi.shakenfun.AlertService" >
<intent-filter >
<action android:name="android.intent.action.MUSIC_PLAYER" />
</intent-filter>
</service>
请不要让我知道,我哪里做错了。
Please do let me know, where I am doing wrong.
我的目标平台是8
谢谢,
拉梅什
Thanks, Ramesh
推荐答案
MediaStore.INTENT_ACTION_MUSIC_PLAYER是德$ P $从API 15 pcated新的code是:
MediaStore.INTENT_ACTION_MUSIC_PLAYER is deprecated from API 15 the new code is:
try {
String pkgname = "com.sec.android.app.music";
PackageManager pkgmanager = getPackageManager();
Intent intent = pkgmanager.getLaunchIntentForPackage(pkgname);
startActivity(intent);
} catch(Exception e) {
// music player not found
}
只需添加您的按钮侦听此code,它会调用默认的音乐播放器。
Just add this code on your button listener and it will call the default music player.
这篇关于安卓:通过启动服务音乐播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文