Reputation: 41
I've got one question regarding the intent action ACTION_CALL
.
What is the correct way of getting back to the own application/activity after the user ends the call?
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" +m1));
startActivity(intent);
I have made the call using the above code. Please provide me with a solution to call my own activity after the call action.
Upvotes: 3
Views: 2263
Reputation: 1834
I run with the same problem, and ended up solving it like this:
public class CallTracker extends PhoneStateListener implements Runnable {
private Context mActivity;
private Callback mCallback;
public interface Callback {
void onCallEnded();
}
public CallTracker(Activity activity) {
super();
mActivity = activity;
if (mActivity instanceof Callback) {
mCallback = (Callback) mActivity;
}
}
@Override public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_IDLE) {
mCallback.onCallEnded();
}
}
public class CallerActivity extends AppCompatActivity implements
CallTracker.Callback {
@Override public void onCallEnded() {
Toast.makeText(this, "Call ended!", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 0
Reputation: 6023
AFter the endofcall.......it just had to come back to the activity..!! you can handle that one onRestart();
Upvotes: 0
Reputation: 20269
unfortunately some phones have settings to force going into for example the Call Log after a call...
However, you can run a loop after your startActivity
to check TelephonyManager.getCallState
, and when it's again TelephonyManager.CALL_STATE_IDLE
, you can restart your own Activity
be sure to add some sleep to the loop
Upvotes: 3