電話をかけたいのですが、通話が終わったら、通話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
通話を開始したに戻るにはどうすればよいですか?