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.
Related
I know since KitKat the code to start the SMS app is the following:
String default_sms_package_name = Telephony.Sms.getDefaultSmsPackage(context);
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, body);
if (default_sms_package_name != null) intent.setPackage(default_sms_package_name);
But is there a way to preselect the SMS receiver like the SMS body?
Yes you can use ACTION_VIEW and set as many numbers as you want with address parameter as below.
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address" , new String("0123456789;3393993300"));
smsIntent.putExtra("sms_body" , "Test SMS to Angilla");
startActivity(smsIntent);
message = ((TextView)findViewById(R.id.message)).getText().toString().trim();
number = ((TextView)findViewById(R.id.phone)).getText().toString().trim();
Uri uri = Uri.parse("smsto:" + number);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
//this will cause code to crash with No Activity found to handle Intent
//sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
This code open up the correct user whose phone number I typed but the EXTRA_TEXT message is not pre-populated in the whatsapp text box. What am I doing wrong ?
I am trying to send SMS to multiple recipients viaINTENT. I tried the following to do it:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", etmessage.getText().toString());
intent.setData(Uri.parse("smsto:" + returnedItems));
intent.setType("vnd.android-dir/mms-sms");
mcontext.startActivity(intent);
Where returnedItems is of Contact Numbers
But the problem is that my recipients numbers are not setting on TO section on SMS INTENT where TEXT is displayed on TEXT section.
Make sure that the numbers are seperated by ; .
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:1234456;234567"));
smsIntent.putExtra("sms_body", etmessage.getText().toString());
startActivity(smsIntent);
always works for me!
Did you tried below ?
Intent mIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:999999;888888"));
I also found out ";" is not working in Samsung device. You have to add "," instead of ";" for samsungs devices.
Intent mIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:999999,888888"));
Also check this answer
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:" + pointsList));
smsIntent.putExtra("sms_body", "Hi Friends & Families, My Location is feeling unsafe in this location");
startActivity(smsIntent);
pointsList is something like ArrayList, for example [8777675673,8566463454,7776666664].
It is working fine.
I have solved this by the following way.
Intent intent = new Intent(Intent.ACTION_SEND);
String numbers = "1234567890;9876543210;453678920"
intent.putExtra("address", numbers);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_image)));
The numbers are separated by semi-colon (;). I read in some mobile phones the numbers need to separated by comma (,).
Hope this will help.
I am trying to send text messages to the selected contacts on the phone using the SmsManager but by default it sends the message using the phone GSM message option. My requirement is to show the popup to the user to choose is messaging options such as WHATSAPP, VIBER etc as shown in the image
here is my code
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage("9844598445", null, "Hello There", null, null);
Please help
Try this one
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
What you're doing right now is directly send an SMS through the SDK. If you want to offer the user the option to send it through another installed app, you need to use an Intent:
Uri uri = Uri.parse("smsto:1234567890");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
I am trying to send a jpg image through MMS using an HTC device (2.3.5, HTC Desire HD-Sense), I am using the following snippet
File sendfilepath = new File("file://" + sendfile);
Uri urimms = Uri.fromFile(sendfilepath);
Intent sendIntent = new Intent("android.intent.action.SEND_MSG");
sendIntent.putExtra(Intent.EXTRA_STREAM, urimms);
sendIntent.setType("image/jpeg");
startActivity(sendIntent);
It opens the Messaging app but it does not attach the image. I do not know why? It shows a toast "Cannot load message"
Something like this should work:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mmsto:<number>");
intent.putExtra("address", <number>);
intent.putExtra(Intent.EXTRA_STREAM, urimms);
intent.setType("image/jpeg");
startActivity(intent);
Otherwise these links look to be a little outdated but you should be able to translate everything pretty well:
Android MMS Intent with with Image and body text
http://androidforums.com/application-development/25988-send-image-action_send.html
try this
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/image_4.png"));
sendIntent.setType("image/png");
startActivity(sendIntent);;