我尝试为 android 编写一个程序。我想用我的程序进行调用,然后识别调用状态。使用 Flowing Function,我可以识别挂出状态和应答状态,但它不起作用。我尝试了这个功能,但它也不起作用
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended, need detect flag
// from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
最佳答案
您不能使用 CALL_STATE_IDLE 和 CALL_STATE_OFFHOOK 来做到这一点。 您必须以编程方式检测传出铃声的结束...
关于android - 如何检测拨出电话中的已接听或拒绝状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14879603/