Intent to open SMS app to send SMS to any selected address? - android

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);

Related

Pass sms body to default sms app

I found multiple threads here about this, but none of them are working for me. This is my code:
public void sendSMS (String number, String body) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:" + number));
i.putExtra("abc", body);
startActivity(i);
}
It opens stock SMS app and passes the number to send, but text body is empty.
I also tried this Uri.fromParts(body, number, null) but then the app just crashes.
Replace your code with below code. You are not passing correct keys to detect number and text body for the sms.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
startActivity(intent);
Please read this documentation for detailed information.
Compose an SMS/MMS message with attachment
Try this
Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
If you want to ensure that your intent is handled only by a text messaging app (and not other email or social apps), then use the ACTION_SENDTO action and include the "smsto:" data scheme. For example:
public void composeMmsMessage(String message, Uri attachment) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:")); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
intent.putExtra(Intent.EXTRA_STREAM, attachment);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}

How to send link to default sms app with Intent?

I want to open my default SMS application with intent from my application and to send LINK to some webpage , but when I try code bellow , sms app want recognize link . My current code is
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra(Intent.EXTRA_TEXT, "https://stackoverflow.com/questions/9290737/android-message-intent");
startActivity(smsIntent);
I want something like this:
You can try as below:
Uri smsToUri = Uri.parse( "smsto:" );
Intent smsIntent = new Intent(Intent.ACTION_VIEW, smsToUri);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("sms_body", "https://stackoverflow.com/questions/9290737/android-message-intent");
startActivity(smsIntent);

access to any email inbox from my activity in android

As we use "content://sms/inbox" for sms inbox, do we have anything like this for email.I want to read email from after selecting email client.I tried the following the code
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setType("message/rfc822");
Uri data = Uri.parse("content://mail/inbox");
intent.setData(data);
startactivity(intent);
I dont want to send mail,just to read the mail,So i cant use mailto:
You should use this :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);

How to show the dialog of all the messaging options in android?

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);

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.

Categories

Resources