Android 呼叫接收器的PhoneStateListener在实际设备中不工作
我已经创建了Android 呼叫接收器的PhoneStateListener在实际设备中不工作,android,broadcastreceiver,telephonymanager,phone-state-listener,Android,Broadcastreceiver,Telephonymanager,Phone State Listener,我已经创建了BroadCastReceiver,它监听IncomingCall和Outgoing Calls。尝试在BroadCastReceiver中使用TelephonyManager添加PhoneStateListener,这在Emulator和某些设备上非常有效 它不适用于三星ST 7652。始终返回呼叫状态\u IDLE和传入号码null。为什么会这样 详情如下: public class ReceiverInComingCall extends BroadcastReceiver {
BroadCastReceiver
,它监听IncomingCall
和Outgoing Calls
。尝试在BroadCastReceiver
中使用TelephonyManager
添加PhoneStateListener
,这在Emulator和某些设备上非常有效
它不适用于三星ST 7652
。始终返回呼叫状态\u IDLE
和传入号码null
。为什么会这样
详情如下:
public class ReceiverInComingCall extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
TelephonyManager phone = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
phone.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}
private class MyPhoneStateListener extends PhoneStateListener{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
Log.i("CALL","CALL_STATE_RINGING");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i("CALL","CALL_STATE_OFFHOOK");
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.i("CALL","CALL_STATE_IDLE");
break;
}
}
}
}
打扰我:-
为什么在我调试三星ST7652时,它会在LogCat
中给出类似的东西,否则它会显示完美的调用状态日志
尝试过
。但是,在浏览了关于
PhoneStateListeners
和android.intent.action.PHONE\u STATE
的多个源代码后,它总是给我CALL\u IDLE
和传入号码null,这对我的解决方案也没有帮助障碍
广播接收机
清单
经允许
这不起作用。只调用空闲和脱离挂钩。并且当呼叫被实际接受时没有侦听器。
E/MSimTelephonyManager(621): MSimTelephonyManager sRegistryMsim != null
public class PhoneStateReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String str = intent.getAction();
if ("android.intent.action.PHONE_STATE".equals(str))
inComing(context, intent);
if ("android.intent.action.NEW_OUTGOING_CALL".equals(str))
outGoing(context, intent);
}
private void inComing(Context context, Intent intent){
String callState = intent.getStringExtra("state");
if ("RINGING".equals(callState)){
Log.i(TAG, "RINGING SENDS BUSY");
}else if ("OFFHOOK".equals(callState)){
Log.i(TAG, "OFFHOOK SENDS BUSY");
}else if("IDLE".equals(callState)){
Log.i(TAG, "IDLE SENDS AVAILABLE");
}
}
private void trueCallerOutgoing(Context context, Intent intent)
{
String callState = intent.getStringExtra("state");
if ("RINGING".equals(callState)){
Log.i(TAG, "RINGING SENDS BUSY");
}else if ("OFFHOOK".equals(callState)){
Log.i(TAG, "OFFHOOK SENDS BUSY");
}else if("IDLE".equals(callState)){
Log.i(TAG, "IDLE SENDS AVAILABLE");
}
}
}
<receiver android:name="PhoneStateReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />