How to make a phone call in android and come back to my activity when the call is done?

后端 未结 20 2140
北恋
北恋 2020-11-22 12:59

I am launching an activity to make a phone call, but when I pressed the \'end call\' button, it does not go back to my activity. Can you please tell me how can I launch a c

相关标签:
20条回答
  • 2020-11-22 13:35

    @Dmitri Novikov, FLAG_ACTIVITY_CLEAR_TOP clears any active instance on top of the new one. So, it may end the old instance before it completes the process.

    0 讨论(0)
  • 2020-11-22 13:37

    When PhoneStateListener is used, one need to make sure PHONE_STATE_IDLE following a PHONE_STATE_OFFHOOK is used to trigger the action to be done after the call. If the trigger happens upon seeing PHONE_STATE_IDLE, you will end up doing it before the call. Because you will see the state change PHONE_STATE_IDLE -> PHONE_STATE_OFFHOOK -> PHONE_STATE_IDLE.

    0 讨论(0)
  • 2020-11-22 13:38

    you can use startActivityForResult()

    0 讨论(0)
  • 2020-11-22 13:38

    Try using:

    finish();
    

    at the end of activity. It will redirect you to your previous activity.

    0 讨论(0)
  • 2020-11-22 13:38

    Add this is your xml: android:autoLink="phone"

    0 讨论(0)
  • 2020-11-22 13:39

    This is regarding the question asked by Starter.

    The problem with your code is that you are not passing the number properly.

    The code should be:

    private OnClickListener next = new OnClickListener() {
    
         public void onClick(View v) {
            EditText num=(EditText)findViewById(R.id.EditText01); 
            String number = "tel:" + num.getText().toString().trim();
            Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number)); 
            startActivity(callIntent);
        }
    };
    

    Do not forget to add the permission in manifest file.

    <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
    

    or

    <uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission>
    

    for emergency number in case DIAL is used.

    0 讨论(0)
提交回复
热议问题