How can I know filename of ImageView image?
I want to send it as email attachment.
UPDATE: I don't use images from resources. I have images from android storage(as in contacts app) using:
new Intent(Intent.ACTION_GET_CONTENT, null);
and from camera. Camera is OK - I can get filepath. But storage is question
If the image is a resource that you provide then you can get the path to the image. The format is:
"android.resource://[package]/[res id]"
[package] is your package name
[res id] is value of the resource ID, e.g. R.drawable.example
You can then pass this as an extra in your create e-mail intent like this:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("image/jpeg");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Picture");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://your.package.name/" + R.drawable.example));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Email:"));
The short answer is that you can't, as images can be from a variety of sources. What you can do is get the bitmap cache with the same result of sending the image.
Related
I want from my application to send to facebook and other applications an Image and some text so the user can share them. Currently I put the text and the image URI but when I choose facebook only the image is sent. In whatsApp also only the image is sent. In Google+ application both image and text are passed. Can someone show me the right direction?
Code example ( I don't have the original code here with me now, maybe I'll post it later)
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_TEXT , myText);
startActivity(Intent.createChooser(shareIntent, "Choose an app" ));
If I change ACTION_SEND to ACTION_SEND_MULTIPLE then it does not work at all. If I change type to "text/plain" or html then text is sent to whatsapp, google+ and Facebook messenger, but NOT in normal Facebook app ( it opens an empty share dialog).
You should use below lines
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My image");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename_toshare)));// this is for image . here filename_toshare is your file path.
sendIntent.putExtra(Intent.EXTRA_TEXT, "My Image ");// this is for text
startActivity(Intent.createChooser(sendIntent, "Email:"));
hope this helps you.
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.
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.
I want to give the user the possibility to share a Image and a Text with Twitter and Facebook.
Actually my code can launch Android's share intent and if the user selects Facebook, all works fine, the Image is attached and the text is shown on the body of the new status.
But something is wrong with Twitter, if i only put a Image all works fine, the image is detected by twitter and automatically uploaded to twipic, then twitter posts the link of the image on the tweet. But if i put a image and a text, then, twitter doesn't detect the image and it only puts the text on the tweet, the image is ignored. What is wrong?
this is my code:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file:///sdcard/image.jpg");
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
You can still try with ACTION_SEND, without using the ACTION_SEND_MULTIPLE.
ACTION_SEND_MULTIPLE resulted in a force close, when I tried to create new intents for sharing to Gmail, G+, etc.
This worked perfect for me:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri uri = Uri.parse("file:///sdcard/image.jpg");
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;
Specify MIME type also for the text. "text/plain" is the type of text data MIME. Try using "*/*" as MIME, so you can send any generic data type.
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
More info about ACTION_SEND_MULTPLE and handling MIME types:
http://developer.android.com/reference/android/content/Intent.html
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.