在拨出电话的情况下,会自动抛出摘机状态嗨,伙计们,首先我为我的英语道歉。
好吧,在我的应用程序中,我正在监视每个呼叫,之前和之后。但是就在通话开始之后,所以我与“响铃”状态无关,但是我的应用程序正在触发一个假的“摘机”状态。当我拨打电话(拨出电话)时,我的应用程序在振铃后立即设置摘机状态。有了这个,我正在监视一个我不应该的呼叫,因为该呼叫无法应答。
有人已经有这个问题了吗?
AndroidManifest.xml
<receiver
android:name=".CallStateBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<receiver
android:name=".OutgoingCallBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
CallStateBroadcastReceiver:
CallStatePhoneStateListener phoneListener = new CallStatePhoneStateListener(context, intent);
TelephonyManager telephony = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
CallStatePhoneStateListener:
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// do something
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// do something
break;
case TelephonyManager.CALL_STATE_RINGING:
// do something
break;
}
OutgoingCallBroadcastReceiver:
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle == null)
return;
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
// just save the number
}