2

我想打个电话,通话结束后我想回来Activity打电话的人。

开始通话的代码:

// Start a call
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(callIntent);

处理返回活动的代码:

// Monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {

    private boolean isPhoneCalling = false;

    String TAG = "PhoneCallListener";

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        // If call ringing
        if (state == TelephonyManager.CALL_STATE_RINGING) {

            Log.d(TAG, "Call ringing, number : " + incomingNumber);
        }
        // Else if call active
        else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

            Log.d(TAG, "Call active");

            isPhoneCalling = true;
        }
        // Else if call idle
        else if (state == TelephonyManager.CALL_STATE_IDLE) {

            Log.d(TAG, "Call idle");

            if (isPhoneCalling) {

                isPhoneCalling = false;

                // Finish native call application to come back to this
                // activity
                Intent i = new Intent(getIntent());
                i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(i);
            }

        }
    }
} 

使用finish()不起作用。它保持随叫随到的应用程序。

我如何回到Activity那个开始的电话?

4

0 回答 0