【发布时间】:2013-12-09 10:51:10
【问题描述】:
我在我的应用程序中构建了一个小型远程控制服务来控制我的应用程序中的默认音乐播放器。我可以使用该方法播放、暂停、跳过和向后移动
private void remoteControl(String CMD) {
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", CMD);
getActivity().sendBroadcast(i);
}
以及以下命令。
public static final String CMDTOGGLEPAUSE = "togglepause";
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";
public static final String CMDNAME = "command";
public static final String CMDSTOP = "stop";
public static final String CMDPLAY = "play";
在我的清单中我有这个权限
<uses-permission android:name="android.permission.WAKE_LOCK"/>
目前,如果我的音乐播放器正在运行或在任务管理器中可用,我可以使用所有控件。但是,如果用户尚未启动音乐播放器进程,则它不起作用。无论如何我可以强制音乐播放器开始播放,即使该过程以前没有启动过而不离开我的应用程序。
【问题讨论】:
标签: android android-manifest android-broadcast android-music-player android-wake-lock