由网友(別扯、扯多了都是事故)分享简介:在我的活动,但我完成活动后使用电话监听器的IM,AFER用户拨打一个电话,我的电话监听器没有死,再次布里格后续活动!请帮助我。phoneListener =新PhoneCallListener();telephonyManager =(TelephonyManager)TransferActivity.this.ge...
在我的活动,但我完成活动后使用电话监听器的IM,AFER用户拨打一个电话,我的电话监听器没有死,再次布里格后续活动!请帮助我。
phoneListener =新PhoneCallListener();
telephonyManager =(TelephonyManager)
TransferActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
PhoneCallListener类:
私有类PhoneCallListener扩展PhoneStateListener {
布尔isPhoneCalling = FALSE;
@覆盖
公共无效onCallStateChanged(INT状态,串incomingNumber){
如果(TelephonyManager.CALL_STATE_RINGING ==州){
}
如果(TelephonyManager.CALL_STATE_OFFHOOK ==州){
isPhoneCalling = TRUE;
}
如果(TelephonyManager.CALL_STATE_IDLE ==州){
如果(isPhoneCalling){
isPhoneCalling = FALSE;
意向意图= getIntent();
startActivity(意向);
}
}
}
}
}
解决方案
该文件说:
要注销侦听,通过侦听器对象,并设置事件参数LISTEN_NONE(0)。
下面是链接到文档
im using a phone call listener in my activity but after finishing my activity , afer user make a call, my phone call listener not dead and brig up activity again !! please help me.
phoneListener = new PhoneCallListener();
telephonyManager = (TelephonyManager)
TransferActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
PhoneCallListener class :
private class PhoneCallListener extends PhoneStateListener {
boolean isPhoneCalling = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
if (isPhoneCalling) {
isPhoneCalling = false;
Intent intent = getIntent();
startActivity(intent);
}
}
}
}
}
解决方案
The documentation says:
To unregister a listener, pass the listener object and set the events argument to LISTEN_NONE (0).
Here is the link to the Doc
相关推荐
最新文章