sending email per intent => is there a length limit? - android

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, ""));
}
}

Related

Send email intent with image in html body

Is it possible to send an email, using an intent, with an image in the body.
I'm using an image that is hosted...
public void sendEmail(View view){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_SUBJECT, "Image in body test");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getHtmlBody()));
startActivity(Intent.createChooser(intent, "Send Email"));
}
private String getHtmlBody() {
String html = "<h1><img width=\"100\" src=\"http://cdn2-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-8.jpg\"> Hello World </h1>";
return html;
}
I am able to do this using javaMail but that sends the email automatically without the user being able to see anything so I'm hoping I can use intents.
There is EXTRA_HTML_TEXT that allows you to supply HTML as alternative to the text in EXTRA_TEXT. However, there's no guarantee that the receiving app supports this extra (hence the requirement that EXTRA_TEXT must be present, too).
The code could look something like this:
public void sendEmail(View view){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Image in body test");
intent.putExtra(Intent.EXTRA_TEXT, getTextBody());
intent.putExtra(Intent.EXTRA_HTML_TEXT, getHtmlBody());
startActivity(Intent.createChooser(intent, "Send Email"));
}
private String getHtmlBody() {
return "<h1><img width=\"100\" src=\"http://cdn2-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-8.jpg\">"
+ getTextBody() + "</h1>";
}
private String getTextBody() {
return "Hello world";
}
Apps that don't support HTML will simply use the text from EXTRA_TEXT.
The answer by Arpit Garg in this post shares that and tags do not work in most email clients, so unfortunately your code wont work. I just tested your code with the Gmail app and a few others and it pulled in a placeholder but not the actual image. what you can do though is add an image as an attachment.

Sending message to Multiple Persons using send intent android

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

Sending Message to Multiple Numbers using Intent

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

Tabs in StringBuilder don't work when sending an e-mail (Android)!

Bit of a weird on this; I my app I am using StringBuilder to build Strings to create an e-mail.
Now what I am trying to do is send the e-mail with parts of text tabbed (the text is to be transferred into a Word Document and this would save a lot of editing).
So in my code I am writing code to include the tabs, for example:
message.append(component).append("\t\t\t\t\t\t\t\t\t\t\t\t").append(risk).append("\r\n");
I use following code to construct the e-mail:
private void sendEmail(String recipient, String subject, String message) {
try {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.setType("message/rfc822");
if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} catch (ActivityNotFoundException e) {
// cannot send email for some reason
}
}
So when I look at the e-mail before sending, the tabs seem to have worked, but when I receive the e-mail, they are not there. Boo.
Any ideas why this might be?
Just have tried your code, it seems tab symbols trimmed while email sends.
Also tried this way and it works fine (in gmail), but it ugly solution
private String tab(){
return " "; // return four space characters
}
message.append(tab()+tab+tab());

Android Button onclick submit to email

I have been working with Java and Xml for a few months now, and have learned a great deal thanks to everyones help on StackOverflow.
My question is about java programming for android in relation to the submit button.
Currently I am trying to figure out how to submit a value to an email address (behind the scenes)
Lets say we have a text field and a button; I want to take the value entered in the text field, and submit that to an email address onclick.
I am unable to find anything online that shows me how to do this.
Thank you in advance for reading through my post and I look forward to your suggestions.
This is a great example of how using Intents can come in great handy!
Android has a bunch of pre-defined Intents that do certain things within the system; you may have clicked on a picture before and a dialog popped up asking whether you would like to view it in your gallery or in a third-party app such as Astro. The viewing of an image has its own pre-determined intent.
Sending an email also has its own pre-determined intent: android.content.Intent.ACTION_SEND. You'll need to create an intent with that property and then attach extra information (ie. the address to send to, the subject/message body, etc.).
Example code:
// Data members
private Intent emailIntent;
private String feedback;
private EditText feedbackBox;
// Create the Intent, and give it the pre-defined value
// that the Android machine automatically associates with
// sending an email.
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
// Put extra information into the Intent, including the email address
// that you wish to send to, and any subject (optional, of course).
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"your_email#whatever.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Insert subject here");
// Acquire feedback from an EditText and save it to a String.
feedback = feedbackBox.getText().toString();
// Put the message into the Intent as more extra information,
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, feedback);
// Start the Intent, which will launch the user's email
// app (make sure you save any necessary information in YOUR app
// in your onPause() method, as launching the email Intent will
// pause your app). This will create what I discussed above - a
// popup box that the user can use to determine which app they would like
// to use in order to send the email.
startActivity(Intent.createChooser(emailIntent, "Insert title for dialog box."));
I hoped this helped!!
Some sources you might like to check out:
http://developer.android.com/guide/topics/intents/intents-filters.html
http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, someEditText.getText());
startActivity(Intent.createChooser(emailIntent, "Send someone an email..."));
try this
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:Type email address here"));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
It works good
String mail=mailid.getText().toString();
String msubject=subject.getText().toString();
String mbody=body.getText().toString();
Log.i("Send email", "");
String[] TO = {mail};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Static subject "+ msubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, "Static body "+ mbody);
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}

Categories

Resources