1

我想用默认的音乐播放器播放一些音频文件。如本文所述,我尝试了以下代码:

    Intent intent = new Intent();  
    ComponentName comp = new ComponentName("com.android.music", "com.android.music.MediaPlaybackActivity");
    intent.setComponent(comp);
    intent.setAction(android.content.Intent.ACTION_VIEW);  
    File file = new File(songPath.toString());  
    intent.setDataAndType(Uri.fromFile(file), "audio/*");  
    startActivity(intent);

但是,我收到了带有以下日志的 ActivityNotFound 异常:

07-12 11:28:49.575: E/AndroidRuntime(22700): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jusplay/com.example.jusplay.playdb}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.music/com.android.music.MediaPlaybackActivity}; have you declared this activity in your AndroidManifest.xml?
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.os.Looper.loop(Looper.java:130)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.ActivityThread.main(ActivityThread.java:3701)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at java.lang.reflect.Method.invoke(Method.java:507)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at dalvik.system.NativeStart.main(Native Method)
07-12 11:28:49.575: E/AndroidRuntime(22700): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.music/com.android.music.MediaPlaybackActivity}; have you declared this activity in your AndroidManifest.xml?
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.Activity.startActivityForResult(Activity.java:2827)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.Activity.startActivity(Activity.java:2933)
07-12 11:28:49.575: E/AndroidRuntime(22700):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)

我无法弄清楚为什么会发生这种崩溃!

4

0 回答 0