Reputation: 377
I want a calling and sms sending onclick of single button. Right now I am able send either sms or call. But I want when user clicks on the button, it should ask for both , Call or SMS. And let the users selects. Phone or SMS. How can I acheive this?
Upvotes: 0
Views: 893
Reputation: 4348
agree with @suresh.
add the following code with his answer.
inside onCall method code to call
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phone));
startActivity(callIntent);
inside onSms method code to sms
// To start launch the sms activity all you need is this:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
// You can add extras to populate your own message and such like this
sendIntent.putExtra("sms_body", x);
//then just startActivity with the intent.
startActivity(sendIntent);
Upvotes: 1
Reputation: 414
Create alert dialog and show it when user click a button
Try Below code
public void popup(final int pos) {
// load detail view of contacts
final CharSequence[] items = { "Call", "SMS", "Locate", "View Details" };
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Action");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Call")) {
// invoke call functionality
onCall(pos);
}
if (items[item].equals("SMS")) {
// invoke sms functionality
onSms(pos);
}
}
});
AlertDialog alert = builder.create();
alert.show();
alert.setCanceledOnTouchOutside(true);
}
Upvotes: 4
Reputation: 3382
You have to implement your own chooser (a dialog). When the user clicks on the button, you show them your dialog and then he/she can select or phone or sms.
Upvotes: 0