I am trying to use the android share intent from my application.
I have listed all the contacts from my contacts content provider in my application.
Now i want to send message to all the contacts i have selected(in my app) using any of the message app
installed in user phone.
I do not want to user smsmaanger , simply want to user any sms sending application in user mobile if
available.
I tried to do with email works great but not with sms .
I tried with email as works great
public static void send(Context ctx, String[] addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
For sms i am using like this .
public static void send(Context ctx, String addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
I just simply want to add my all contacts to users message app for sending message, with a message
possible
To send SMS to multiple numbers you need to separate the numbers with ;
Sample here:
String toNumbers = "";
ArrayList<String> numbersArrayList;// your phone numbers here
for ( String number : numbersArrayList)
{
toNumbers = toNumbers + number + ";"//separating numbers with semicolon
}
toNumbers = toNumbers.subString(0, toNumbers.length - 1);// remove the last semicolon
...
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER, toNumbers);
Related
I'm using the following code to send an email in my app.
public void sendEmail() {
emailSent = 1;
String to = toEmail.getText().toString();
String subject = getUser() + " - User Feedback";
String message = bodyTxt;
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("message/rfc822");
try {
startActivity(Intent.createChooser(email, "Send Email..."));
} catch (android.content.ActivityNotFoundException ex) {
String msg = ex.getMessage().toString();
emailSent = 2;
Toast.makeText(this, "There was a problem sending this email, please try again.", Toast.LENGTH_SHORT).show();
}
}
The email.setType() presents a screen offering options for which method to send the message including email. This works fine if the user selects email as a copy of the email comes up and the user can then send it. However, if the user doesn't do anything and simply uses the back space it returns to the app and assumes the email has been sent. How can I test for the user not sending the email?
You could startActivityForResult() and listen for a RESULT_OK in onActivityResults. But there is no framework requirement that forces the email app to setResult appropriately. So your mileage may vary based on the email client app.
I'm developing an application that can send message through whatsapp. I have implemented it by following this answer but it only works for contacts that on my contact list. It keeps error when i try to send message to contacts that are not in my contact list although the user already registered on whatsapp using that number (contact). Here is the message from whatsapp:
here is my code:
try {
Uri uri = Uri.parse("smsto: " + smsNumber);
//Timber.e("smsNumber %s", uri.toString());
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
} catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
is there any solutions ?
you can send via WhatsApp API even if he is not in your contact
String whatsappUrl = String.format("https://api.whatsapp.com/send?phone=%s&text%s",PhoneNumber,msg);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(whatsappUrl));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
p_context.startActivity(browserIntent);
I've written a function, for sending an email via intent. On my phone, gmail is installed, so the first part of this function is used... I want to send my database as a csv file, so it's quite a big string. If I send all data at once, NOTHING happens (no exception, no mail program that appears). If I split my data into two parts and send them one after another, it works. So there seems to be a limitation for the text.
Does anyone know what the limit is? Or is there another problem I'm not aware of?
public static void sendMailWithIntent(Activity activity, String subject, String text, boolean textIsHtml, String receiver)
{
try
{
Intent sendMailtoGmail = new Intent(Intent.ACTION_SEND);
sendMailtoGmail.setType("plain/text");
sendMailtoGmail.putExtra(Intent.EXTRA_EMAIL, new String[] {
receiver
});
sendMailtoGmail.putExtra(Intent.EXTRA_SUBJECT, subject);
sendMailtoGmail.putExtra(Intent.EXTRA_TEXT, textIsHtml ? Html.fromHtml(text) : text);
sendMailtoGmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
activity.startActivity(Intent.createChooser(sendMailtoGmail, ""));
}
catch (android.content.ActivityNotFoundException ex)
{
Intent sendGeneric = new Intent(Intent.ACTION_SEND);
sendGeneric.setType("plain/text");
sendGeneric.putExtra(Intent.EXTRA_EMAIL, new String[] {
receiver
});
sendGeneric.putExtra(Intent.EXTRA_SUBJECT, subject);
sendGeneric.putExtra(Intent.EXTRA_TEXT, textIsHtml ? Html.fromHtml(text) : text);
activity.startActivity(Intent.createChooser(sendGeneric, ""));
}
}
I have installed the telegram app and just want to send a message (string) from my app through telegram to a contact.
All I found yet is in the question: How to send a Intent with telegram
with the code:
//Sending message
void intentMessageTelegram(String msg)
{
final String appName = "org.telegram.messenger";
final boolean isAppInstalled = isAppAvailable(this.getApplicationContext(), appName);
if (isAppInstalled)
{
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.setPackage(appName);
myIntent.putExtra(Intent.EXTRA_TEXT, msg);//
this.startActivity(Intent.createChooser(myIntent, "Kevin"));
}
else
{
Toast.makeText(this, "Telegram not Installed", Toast.LENGTH_SHORT).show();
}
}
when I use that the telegram opens a contact list. But choosing multiple contacts, It is not sending it to them. If I click on one of them the message will be sent.
How can I send a message without displaying the telegram?
Is there a way to read messages too?
Thanks in advance^^
Hi i have a list of numbers.
ArrayList<String> numbers;
I want to sent message to all these number using Intent, together .
I did this with email like sending email to multiple people , How to do for message ?
public static void send(Context ctx, String[] addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
This is opening the message app but the numbers stored in addy are not listed in message sent to column
I did this with email like sending email to multiple people
Assuming that you used a third-party application via an Intent action, whether this works is up to the author of the third-party application. You have no way of knowing whether each of the hundreds of email apps for Android support specifying multiple addresses, unless you test them all.
How to do for message ?
You send them one at a time.
Your code is dreadful, using an undocumented MIME type that will not necessarily be honored on all devices, but EXTRA_PHONE_NUMBER is supposed to be a String, not a String[].
ACTION_SEND, or ACTION_SENDTO with an smsto: address, similarly is only guaranteed to support a single number and will give you the same problems as you have with sending email that way.
SmsManager has methods for directly sending SMS; they too only support one phone number at a time.
for java developer use
public static void send(Context ctx, String[] address, String subject,
String body, File attachment) {
List<String> mylist = Arrays.asList(address);
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
StringJoiner sj = new StringJoiner(";", "smsto:", "");
mylist.forEach(sj::add);
sendIntent.setData(Uri.parse(sj.toString()));
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
if(sendIntent.resolveActivity(ctx.getPackageManager()) != null) {
ctx.startActivity(sendIntent);
}
}
for those using kotlin, use
fun send(ctx: Context, address: Array<String>, subject: String, body: String, attachment: File) {
val sendIntent = Intent(Intent.ACTION_VIEW)
val data = address.toList().joinToString(";", "smsto:")
sendIntent.data = Uri.parse(data)
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject)
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body)
if(sendIntent.resolveActivity(ctx.packageManager) != null) {
ctx.startActivity(sendIntent)
}
}