2

I want to use default phone number and pass that in alert dialog.How it's possible. I have tried,but it force close.Please solve my issue. Thanks in advance. My coding is as follows:

case R.id.menu_settings:
String phoneNo ="123456789";
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("Do you want to call us?"+phoneNo);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
String uri = "123456789";
public void onClick(DialogInterface dialog, int whichButton) {
    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse(uri));
    startActivity(intent);
 }
});
alert.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        finish();
    }

  });
  alert.show();
return true;
}
return false;
}
Linga
  • 10,379
  • 10
  • 52
  • 104
  • Post the logcat stacktrace too. – Siddharth Lele Feb 08 '13 at 04:04
  • Duplicate. [Here](http://stackoverflow.com/questions/5551912/android-how-to-call-the-number-by-android-application) and [here](http://stackoverflow.com/questions/4275678/how-to-make-phone-call-using-intent-in-android) – cnexus Feb 08 '13 at 04:09

2 Answers2

0

The Uri should be in the format tel:########

String uri = "tel:123456789";
cnexus
  • 454
  • 1
  • 3
  • 14
Rajesh
  • 15,724
  • 7
  • 46
  • 95
0

This is happening because at least 1 of 2 reasons.

  1. You do not have the permission <uses-permission android:name="android.permission.CALL_PHONE"/> in your manifest

  2. Your Uri is in an incorrect format. Change it from
    String uri = "123456789" to
    String uri = "tel:123456789"

cnexus
  • 454
  • 1
  • 3
  • 14