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.
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);
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);
}
}
Couldn't find the answer to my problem, so here is my question:
I have an app storing debts and where i can send the debt info to anyone using ShareActionProvider in the actionbar. It all works fine, i can send a string via, let's say, whatsapp. So far, so good. I wanted to include a link to the app in the play store at the end of the message but couldn't find out how to do it.
Here the intent I'm sending via the ShareActionProvider
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message);
i.setType("text/plain");
How can i achieve to add something like this:
Don't forget to check out this
just append the link to the end.
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=" + getPackageName());
i.setType("text/plain");
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
i.setType("text/plain");
I need to show/interact with a new contact before create it, and I need a simple way to add it to the phone contacts.
this is the code I use:
String contactPhone = "33333333";
Uri contactUri = Uri.parse(String.format("tel: %s", contactPhone));
Intent addContactIntent = new Intent(
ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, contactUri);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "FirstName" );
addContactIntent.putExtra(ContactsContract.Intents.Insert.COMPANY,"CompanyName");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,contactPhone);
addContactIntent.putExtra(ContactsContract.Intents.Insert.EMAIL,"contact#email.com");
startActivity(addContactIntent);
and this is the result. The problem is that the Intent show me only the Phone instead all the info added.
ContactsContract.Intents.Insert.ACTION if you want to interact before create it:
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION,ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.NAME, getName());
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, getCompany());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, getEmail());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, getPhone());
intent.putExtra(ContactsContract.Intents.Insert.POSTAL, getAddress());
startActivity(intent);
This works pretty well. I hope this will help you.
This site (http://wiresareobsolete.com/2011/10/simplifying-interaction-with-contacts/) shows and gives examples) that SHOW_OR_CREATE_CONTACT can only trigger off "tel" or "mailto"/email for searches.
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.