开发者

how to come back to my application after ACTION_CALL in android

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?

开发者_StackOverflowIntent 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.


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


AFter the endofcall.......it just had to come back to the activity..!! you can handle that one onRestart();


I run with the same problem, and ended up solving it like this:

  1. Make a Callback interface with single (or multiple if you want) methods
  2. Implement that interface in your activity
  3. Make a reference to that interface inside PhoneStateListener class
  4. Call a method within that interface when the call ended

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜