简体   繁体   中英

sms application intent not working in android 3.0 and above

This is the piece of code I am using to call the SMS application:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
            intent.putExtra("sms_body", body);
            intent.putExtra("compose_mode", true);
            launchIntent(intent);

On devices with an os version below Android 3.0, the above code is working fine, the SMS page gets opened and the message to be sent and the numbers get prefilled correctly but in Android 3.0 and above devices this is not working anymore.

In Android 3.0 the SMS intent is called and the number gets filled and not the text where as in Android 4.0 the SMS intent is called and the text gets filled and not the number.

Does anyone know the solution for this problem?

This code will works for all versions of android

String smsBody = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

Following code works perfect

                String body = "This is the message i need to send";
                String num  = "smsto:999416231";
                String[] tokens = num.split(":");
                Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                sendIntent.putExtra("address",tokens[1]);
                sendIntent.putExtra("sms_body", body); 
                sendIntent.setType("vnd.android-dir/mms-sms");
                startActivity(sendIntent);  

The code which i have mentioned in my question is use to pass the number as Uri.parse(uri) and its value is "smsto:9941..."

But in the new code i am splitting the text and number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM