I'm having this issue where sharing an image from my app to Gmail puts the path of the image in the To field.
Here's the code that I'm using:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_SUBJECT,"Beam Dental Insurance Card");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
shareIntent.setDataAndType(insuranceCardImageUri, getActivity().getContentResolver().getType(insuranceCardImageUri));
shareIntent.putExtra(Intent.EXTRA_STREAM, insuranceCardImageUri);
startActivity(Intent.createChooser(shareIntent, "Share Insurance Card"));
And here's what I get.
The To: field gets filled in with the path to the image with the "content:" removed from the front. I've tried setting the EXTRA_EMAIL on the intent but that doesn't help.
First, replace:
shareIntent.setDataAndType(insuranceCardImageUri, getActivity().getContentResolver().getType(insuranceCardImageUri));
with:
shareIntent.setType(getActivity().getContentResolver().getType(insuranceCardImageUri));
as ACTION_SEND does not use a Uri in the data field of the Intent.
Then, remove:
shareIntent.setType("image/*");
as you do not need to call setType() twice (or even call setType() and setDataAndType(), as you have it here).
Also, bear in mind:
If the Uri is not coming from your app (e.g., your own ContentProvider), third-party apps like Gmail may not be able to use it, as they may not have permission to access it. This is not significantly different than passing a URL to a third-party app, where the URL requires an authenticated user session to be useful.
There is no requirement for ACTION_SEND implementations to honor both EXTRA_STREAM andEXTRA_TEXT`.
You can share image using share intent, but you've to decode image to a localized Bitmap
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = Images.Media.insertImage(getContentResolver(), loadedImage, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
loadedImage is the loaded bitmap from http://eofdreams.com/data_images/dreams/face/face-03.jpg
acoording to Nitin Misra
Related
I have been trying to share some images to facebook using the ACTION_SEND_MULTIPLE Intent.
The code that i wrote for this is.
ArrayList<Uri> imageUris = new ArrayList<Uri>();
for (DeviceImage image : catchImagesURI) {
Log.d(TAG, "onClickShareFB: image uri " + image.getImageURI());
imageUris.add(image.getImageURI());
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/png");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
}
where the Uri of the images are /storage/emulated/0/DCIM/Screenshot_1497529599.png and /storage/emulated/0/DCIM/calendar.png
When i choose Facebook from the options i get
Is there something wrong with the format of the Image Uri or am i doing this completely wrong?
Is there something wrong with the format of the Image Uri
They are not valid Uri values. A Uri has a scheme. For example, https://stackoverflow.com/questions/46152988/sharing-to-facebook-with-action-send-multiple is a Uri with a scheme of https. Given the paths that you are using, presumably the scheme should be file.
Whether Facebook can use file Uri values pointing to external storage is a separate matter. Probably it can.
Its pretty clear in the documentation that you can send multiple pieces of data with:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
but it seems, from that one line: shareIntent.setType("image/*"); that all pieces have to be the same data type. What If I wanted to send a picture(image/jpeg) and a hashtag that should go along with in the caption (text/plain)?
How would I handle multiple kinds of content in one shareIntent? Is it possible to send 2 shareIntents to the same activity? How would I handle this?
If your goal is to share one picture with text, this is the code I would suggest:
String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, pictureUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));
It's not exactly clear from the question whether you want to send multiple images or just a single image, but with an associated text.
In the first case (multiple images):
Use ACTION_SEND_MULTIPLE and provide the list of uris as EXTRA_STREAM, as in:
Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
If it's the second case (image plus text):
Use just ACTION_SEND and provide both EXTRA_STREAM and EXTRA_TEXT, for example:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
If, however, you need to share streams of varying MIME types (such as both pictures and other attachments) just use a more generic MIME type, such as */*. For example:
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
shareIntent.setType("*/*");
From the documentation of ACTION_SEND_MULTIPLE (emphasis mine):
Multiple types are supported, and receivers should handle mixed types
whenever possible. The right way for the receiver to check them is to
use the content resolver on each URI. The intent sender should try to
put the most concrete mime type in the intent type, but it can fall
back to <type>/* or */* as needed.
e.g. if you are sending image/jpg and image/jpg, the intent's type can
be image/jpg, but if you are sending image/jpg and image/png, then the
intent's type should be image/*.
This works when mixing, say, images and downloaded files.
The question is (might be a repeated one), but I could not find a proper answer to it, so asking here again.
In my application, I need to share both an image and a text file using a single intent.
I read a few answers, like:
ACTION_SEND sending both an Image and Text in the same Intent,
Send Image and Text both using ACTION_SEND or ACTION_SEND_MULTIPLE
and also Problems sharing combined text and image with SHARE INTENT
and tried to implement the given solutions in my application, but none of them worked for me.
The code I've implemented so far is as below :
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_SUBJECT, "I found movie "+movieTitle+" on Movies Tracker!");
share.putExtra(Intent.EXTRA_TEXT, "my text");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(share, "Share via"));
So now my question is: is there any way to share both an image and a text file with single intent?
If it's possible, then please help regarding this issue.
Thanks in advance.
try this one
private void initShareIntent(String type,String _text){
File filePath = getFileStreamPath("<span class="skimlinks-unlinked">shareimage.jpg</span>"); //optional //internal storage
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath))); //optional//use this when you want to send an image
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
}
Here is my problem... I want to share a png image. I have the image in drawable and assets. When I use the sharingIntent it works but not in the way that I want. The file shared appears with numbers and without extension and some apps send the message "unknow file". What can i do??
this is my code:
Uri uri = Uri.parse("android.resource://com.example.shareimages/" + R.drawable.caja);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "send"));
I tried to use instead of drawable files, the files in assets ( with this "file:///android_asset/...) but it didn't work
Try something like this:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");
// For a file in shared storage. For data in private storage, use a ContentProvider.
Uri uri = Uri.fromFile(getFileStreamPath(pathToImage));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent)
If you want to share it via the assets folder, you'll have to use a ContentProvider. See this answer on how to do so:
https://stackoverflow.com/a/7177103/1369222
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