android音乐播放器监听器,android 音乐播放器电话监听
正好用到整理下首先 添加 权限电话监听/**** @author xiaoma* 电话监听器类*/private class MobliePhoneStateListener extends PhoneStateListener {@Overridepublic void onCallStateChanged(int state, String incomingNumber) {switch (s
正好用到整理下
首先 添加 权限
电话监听
/**
*
* @author xiaoma
* 电话监听器类
*/
private class MobliePhoneStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE: // 挂机状态
Intent intent = new Intent(PlayerActivity.this, PlayerService.class);
playBtn.setBackgroundResource(R.drawable.play_selector);
intent.setAction("com.xiaoma.media.MUSIC_SERVICE");
intent.putExtra("MSG", AppConstant.PlayerMsg.CONTINUE_MSG);//继续播放音乐
startService(intent);
isPlaying = false;
isPause = true;
break;
case TelephonyManager.CALL_STATE_OFFHOOK://通话状态
case TelephonyManager.CALL_STATE_RINGING://响铃状态
Intent intent2 = new Intent(PlayerActivity.this, PlayerService.class);
playBtn.setBackgroundResource(R.drawable.pause_selector);
intent2.setAction("com.xiaoma.media.MUSIC_SERVICE");
intent2.putExtra("MSG", AppConstant.PlayerMsg.PAUSE_MSG);
startService(intent2);
isPlaying = true;
isPause = false;
break;
default:
break;
}
}
}最后别忘了 添加来电监听事件
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // 获取系统服务
telManager.listen(new MobliePhoneStateListener(),
PhoneStateListener.LISTEN_CALL_STATE); ok,很简单吧 非常感谢 小巫的 简、美音乐 的参考!
更多推荐
所有评论(0)