android:send dynamic image through mail - android

Hi i am making an app in which i am dynamically getting the image from server and i want to give user the option to mail that image. I am using following code but i dont how to set path of image in below code.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.emlSendToFriendSubject));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto});
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.emlSendToFriendBody));
File file = getFileStreamPath(EMAIL_TEMP_FILE);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+file.getAbsolutePath()));
startActivityForResult(Intent.createChooser(emailIntent,getResources().getString(R.string.btnSendToFriend)),ActMain.EMAIL_DONE);

You set the path to the image in this line:
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+file.getAbsolutePath()));
, where file is the image you want to send.
Also, note that the second call to setType will override the effects of the first call you made.

Related

how to send picture through email if we having a picture in base64 format in android?

i want to send picture with message through email and I also want to show that picture in my email body.,i have tried this code but it is not working ,what i do.here is My code:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
emailIntent.setType("text/html");
Uri uri = Uri.fromFile(getFileStreamPath( "<img src=data:image/*;base64,#mediaUrlBase64#\">"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);
here is the photo:-
thankyou...:)
Tried:
I had used bold tag and anchor tag as i shown below these tag are working fine , but when i used img tag i can able to see a square box which say as OBJ:
i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml("<b>Hi</b><a href='http://www.google.com/'>Link</a> <img src='http://url/to/the/image.jpg'>",
imgGetter,
null));
i.setType("image/png");
And also tried this:
"<img src=\"http://images.anandtech.com/doci/3982/HTCSurround-0134.jpg\">"
But no luck. I found some answer from SO and found that unfortunately, it's not possible to do this with Intents.
The reason why for example bold text is displayed in the EditText and not an Image is that StyleSplan is implementing Parcelable whereas ImageSpan does not. So when the Intent.EXTRA_TEXT is retrieved in the new Activity the ImageSpan will fail to unparcel and therefore not be part of the style appended to the EditText.
Using other methods where you don't pass the data with the Intent is unfortunately not possible here as you're not in control of the receiving Activity.

send emailwith html content and image with android

I want to send an email from my android application which have HTML content and also an image.
I have tried this code
Intent mailIntent = new Intent(android.content.Intent.ACTION_SEND);
mailIntent.setType("text/html");
mailIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.subject_mail));
mailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
But i have always an icon "obj" instead of image

Attaching an drawable image to email in android

I have a list of Drawable images in my application and want to send one of the images through mail.
my code looks like
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Picture");
sendIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse(lstPhotos.get(newPosition).getPhotoURL()));
myActivity.startActivity(Intent.createChooser(sendIntent, "Email:"));
But in the above code i have a problem since i cannot get the image URI from the list of drawables.
Can anyone help me how to send the image because if i use the above code i am getting an empty image of 0kb sent.
You can do it by saving that image to a temporary location on internal/external cache directory as an image and then use that image's path in the attachment using Uri.

How to add .pdf extension when sending an attachment from Android?

I am trying to send a pdf as an attachment from Android. Here is the code:
String[] mailto = {"me#gmail.com"};
Uri uri = Uri.parse("android.resource://com.mywebsite.sendemail/raw/mypdf");
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "My Body");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
Now this works but the problem is that the attachment is called mypdf instead of mypdf.pdf. I cannot figure out how to send it with it's extension... That's what I need help with. Thanks.
I am unconvinced what you want will be possible, since you are pulling the PDF from a resource. If you copy the PDF to a local file (with the correct extension) and send that, you should get the extension in the resulting message. But straight out of the resource...I suspect there's no way to add the extension.
When ever I attempt to use the .putExtra methodology it always crashes my application with a "Force Close" message. If I use something like:
String mtUri = "mailto:someone#gmail.com?subject=Some Subject&body=Some text&";
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(mtUri));
startActivity(intent);
It seems to work fine. I do still have the problem of attaching a file and could use some help figurint out the "attachment=file:///..." syntax.
Thanks,

Embedding image in email in Android

Is it possible to programatically embed an image in the body of an email sent by the Mail app in Android?
Can I use the ACTION_SEND intent to do this, or should I compose the email myself?
to put the image in the body, you need to set the content type to "text/html" and then put an img tag in the email body. if you don't want to use a webserver to host the image, then you can use a data uri for the image.
Info & Sample:
<img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />
If you want to attach an image to the email, you use the putExtra method and set it to EXTRA_STREAM.
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, myImageStream);
If your image (or file) is in the SD card, you can proceed as follow:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/your_path_in_the_sd_card/your_image.png"));
startActivity(shareIntent);
If you don't want to send image, you need to modify the MIME in the "setType()" method.
For more details check this post.

Categories

Resources