SMS application does not work in Android 3.0 and higher

This is part of the code that I use 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 os version lower than Android 3.0, the above code works fine, the SMS page opens and the message is sent, and the numbers are filled out correctly, but on Android 3.0 and higher devices this no longer works.

In Android 3.0, an SMS request is called, and the number is filled, not the text, where, as in Android 4.0, the intention is SMS and the text is filled, not the number.

Does anyone know a solution to this problem?

+4
source share
2 answers

The following code works fine

  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 I mentioned in my question is used to pass a number as Uri.parse(uri) , and its value is "smsto:9941..."

But in the new code, I separate the text and the number.

0
source

This code will work 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); 
+1
source

Source: https://habr.com/ru/post/1413293/


All Articles