Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACTION_SEND used to send sms

I want to open native application to send sms but there should be already phone number. I found ACTION_SEND but when I'm calling my function it's return error that:

04-26 11:59:15.991: ERROR/AndroidRuntime(20198): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO (has extras) }

My code presented here:

    private void smsSend(String number) {
    Intent intent = new Intent(Intent.ACTION_SENDTO, null);
    intent.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
    startActivity(intent);
}

I know that's is simple but I don't know why it does not work and I can not find any helfull information.

Thanks for any advice.

like image 446
Robert Avatar asked Apr 26 '11 09:04

Robert


People also ask

How to send sms using Intent in Android?

Intent sendIntent = new Intent(Intent. ACTION_VIEW); sendIntent. putExtra("sms_body", "default content"); sendIntent.

What is action_ send?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.


3 Answers

Why, this should work fine. http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO

Check out my code:

Uri uri = Uri.parse("smsto:0800000123");   
Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body", "The SMS text");   
startActivity(it); 
like image 91
Vivienne Fosh Avatar answered Sep 20 '22 17:09

Vivienne Fosh


Thanks for the info ! Here is my solution using the previous info:

if (url.indexOf("tel:") > -1) {
    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
    return true;
}
else if (url.indexOf("sms:") > -1){
    startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse(url)));
    return true;
}

Best regards.

like image 25
PipiBadenas Avatar answered Sep 19 '22 17:09

PipiBadenas


I think you should use the following code:

Intent sendIntent = new Intent(Intent.ACTION_VIEW);

//use to fill the sms body
StringBuilder uri = new StringBuilder("sms:" + mobilenumber);
sendIntent.putExtra("sms_body", "");
sendIntent.setType("vnd.android-dir/mms-sms");
sendIntent.setData("");
startActivity(sendIntent);

I think this may help you.

like image 21
Anup Rojekar Avatar answered Sep 19 '22 17:09

Anup Rojekar