>我试图获得拨出电话的振铃阶段。我已经尝试过具有NEW_OUTGOING_CALL和PHONE_STATE操作的BroadcastReceiver。但我没有得到接收者的铃声阶段。我现在明白了,接收器不会告诉你振铃阶段。我看到了同样的查询:- 安卓 - 如何检测拨出电话被接听或接听? 我也应用了这个解决方案,但仍然没有得到任何解决方案。我已经声明了带有操作的服务通知侦听器服务我需要做额外的事情或其他事情......
我认为要获得拨出电话的振铃阶段或在另一端接听电话,这是可能的。
请帮忙!
在清单文件中,您应该具有以下权限来检查传出呼叫:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
和广播接收器的代码:
public class PhoneStateChecking extends BroadcastReceiver {
boolean hasCallStateRinging = false;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Intent", intent.toString());
if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
Log.e("CAll-STATUS", "out going Call");
}
// Checking for the call status
try {
// TELEPHONY MANAGER class object to register one listner
TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//Create Listner
MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
// Register listener for LISTEN_CALL_STATE
tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
} catch (Exception e) {
e.printStackTrace();
}
}
private class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if (hasCallStateRinging)
return;
else {
hasCallStateRinging = true;
Log.e("CAll-STATUS", "CALL_STATE_RINGING");
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if(!hasCallStateRinging){
hasCallStateRinging = true;
Log.e("CAll-STATUS", "CALL_STATE_OFFHOOK");
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if (hasCallStateRinging) {
hasCallStateRinging = false;
Log.e("CAll-STATUS", "CALL_STATE_IDLE");
}
break;
}
}
}
}