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

后端 未结 20 2141
北恋
北恋 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:23

    Inside PhoneStateListener after seeing the call is finished better use:

    Intent intent = new Intent(CallDispatcherActivity.this, CallDispatcherActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    

    Where CallDispatcherActivity is the activity where the user has launched a call (to a taxi service dispatcher, in my case). This just removes Android telephony app from the top, the user gets back instead of ugly code I saw here.

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

    If you are going to use a listener you will need to add this permission to the manifest as well.

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    
    0 讨论(0)
  • 2020-11-22 13:28

    To return to your Activity, you will need to listen to TelephonyStates. On that listener you can send an Intent to re-open your Activity once the phone is idle.

    At least thats how I will do it.

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

    // in setonclicklistener put this code:

    EditText et_number=(EditText)findViewById(R.id.id_of_edittext); 
    String my_number = et_number.getText().toString().trim();
    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(my_number)); 
    startActivity(callIntent);
    

    // give permission for call in manifest:

    <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
    
    0 讨论(0)
  • 2020-11-22 13:29
      Intent callIntent = new Intent(Intent.ACTION_CALL);  
      callIntent.setData(Uri.parse("tel:"+number));  
       startActivity(callIntent);   
    
     **Add permission :**
    
     <uses-permission android:name="android.permission.CALL_PHONE" />          
    
    0 讨论(0)
  • 2020-11-22 13:31

    This is solution from my point of view:

    ok.setOnClickListener(this);
    @Override
    public void onClick(View view) {
        if(view == ok){
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:" + num));
            activity.startActivity(intent);
    
        }
    

    Of course in Activity (class) definition you have to implement View.OnClickListener .

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