0

在我的应用程序中,如果使用以下代码收到呼叫,则会启动一个活动:

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);
}

这工作正常 - 通话结束后特定活动启动。但是当我的应用程序没有运行或不在前台并接听电话时出现问题。通话结束后,活动再次启动。任何人都可以帮助我。谢谢?

4

0 回答 0