我注册了一个广播接收器来接收“com.android.music.playstatechanged”和“com.android.music.musicservicecommand”
public void registerMusicServiceCommandReceiver() {
if (mMusicCommandListener == null) {
mMusicCommandListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("com.android.music.playstatechanged")) {
Log.d(TAG, "Music play state changed");
}
if (action.equals("com.android.music.musicservicecommand")) {
String cmd = intent.getStringExtra("command");
Log.d(TAG, "Music Service command : "+cmd+ " received");
if (cmd != null && cmd.equals("play")) {
Log.d(TAG, "received music service cmd, play");
}
if (cmd != null && cmd.equals("pause")) {
Log.d(TAG, "received music service cmd, pause");
}
}
}
};
IntentFilter commandFilter = new IntentFilter();
commandFilter.addAction("com.android.music.musicservicecommand");
commandFilter.addAction("com.android.music.playstatechanged");
registerReceiver(mMusicCommandListener, commandFilter);
}
}
但我只能收到“com.android.music.playstatechanged”,无法收到“com.android.music.musicservicecommand”,谁能解释一下?提前谢谢。