tags:

views:

2559

answers:

4

Hi,

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 call activity which comes back to me when 'End call' button is pressed? This is how I'm making the phone call:

    String url = "tel:3334444";
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));

Thank you.

+4  A: 

Simple answer: you can't.

There are two ways to instantiate a phone call. You can fire off an android.intent.action.CALL Intent with the phone number as the URL (as you're doing) or android.intent.action.DIAL with the phone number as the URL (again). Both of these start the phone app thingy and it won't automatically return control to your app.

fiXedd
A: 

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

    Button ok=(Button)findViewById(R.id.Button01);
    ok.setOnClickListener(next);
}
OnClickListener next = new OnClickListener()
{
    public void onClick(View v)
    {
        EditText num=(EditText)findViewById(R.id.EditText01);

     Intent intent = new Intent(Intent.ACTION_CALL);
     intent.setData(Uri.parse(""+num));

     startActivity(intent);
    }

};

}

this is my code to make call to a number entered in the edit text box. there are no errors but i m not able to perform the call. i have also added the intent in manifest but not able to perform the call action. can any one please tell me a solution.

thanks in advance

starter
please ask a own question for this
Janusz
A: 

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 .

cikabole
A: 

This is regarding the question asked by Starter.

The problem with ur code is that u r 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"

or

uses-permission android:name="android.permission.CALL_PRIVILEGED"

for emergency number in case DIAL is used.

Pria