在我的应用程序中,如果使用此代码收到呼叫,则会启动一项活动:
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
incall = true;
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
if (incall) {
c = TestOnDemo.this;
Intent i = new Intent(TestOnDemo.this,
IncallActivity.class);
startActivity(i);
incall = false;
}
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
incall = true;
} else if (state == 0) {
// Incoming call: Pause music
incall = true;
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
这很好用 - 在通话结束后启动特定的Activity。但有个问题 当我的应用程序没有运行或不在前台并接到电话时。通话结束后,活动再次启动。任何人都可以帮助我。谢谢?