Skip to content Skip to sidebar Skip to footer

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.

Solution 1:

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

Check out my code:

Uriuri= Uri.parse("smsto:0800000123");   
Intentit=newIntent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body", "The SMS text");   
startActivity(it); 

Solution 2:

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.

Solution 3:

I think you should use the following code:

IntentsendIntent=newIntent(Intent.ACTION_VIEW);

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

I think this may help you.

Solution 4:

On my side, the intent without uri parameter work for all devices, except for Pixel Phone where I need to use it, so I check the 2 ways:

IntentsmsIntent=newIntent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    finalContextcontext= activity.getApplicationContext();
    finalStringphoneNumber="1234567890";
    finalStringmsg="Hello!";
    smsIntent.putExtra("address", phoneNumber);
    smsIntent.putExtra("sms_body", msg);
    smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
            Intent.FLAG_ACTIVITY_CLEAR_TOP);

    finalPackageManagermanager= context.getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(smsIntent, 0);
    if (infos.size() <1) {
        //No Application can handle your intent//try in a another way ...Uriuri= Uri.parse("smsto:"+phoneNumber);
        smsIntent = newIntent(Intent.ACTION_SENDTO, uri);
        smsIntent.putExtra("sms_body", msg);
        infos = manager.queryIntentActivities(smsIntent, 0);
    }

    if (infos.size() <1) {
        //No Application can handle your intent
        Log.e("SendMessage","No Application can handle your SMS intent");
    }

Solution 5:

In kotlin following code works with number and custom message

valdefaultSmsPackageName= Telephony.Sms.getDefaultSmsPackage(activity)  
            valsendIntent= Intent(Intent.ACTION_SEND)
            sendIntent.type = "text/plain"
            sendIntent.putExtra("address", "sms:"+contactNumber)
            sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_msg_body))
            Timber.e("defaultSmsPackageName: "+defaultSmsPackageName)
            if (defaultSmsPackageName != null){ //Can be null in case that there is no default, then the user would be able to choose any app that support this intent.
                sendIntent.setPackage(defaultSmsPackageName)
                activity!!.startActivity(sendIntent)
            }

Post a Comment for "Action_send Used To Send Sms"