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.
Related
I am trying to share GIF image that is stored in resource folder, can I share that GIF Directly or in any other
Uri uri = Uri.parse("android.resource://com.myproject/drawable/xyz.gif");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "sharing myapp");
shareIntent.setType("image/gif");
startActivity(Intent.createChooser(shareIntent, "Share from"));
use above code but no any app found in chooser to open gif, but in my default photo gallery i can open that gif and also share.
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
i'm trying to send some images available in asset folder using Intent but it providing error says shared failed try again later please provide me some suggestion.
Here is what i'm doing
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///android_asset/1.jpg"));
startActivity(Intent.createChooser(share, "Share Image!"));
i also trying by using like this
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://com.example.whatsappshare/asset/1.jpg"));
startActivity(Intent.createChooser(share, "Share Image!"));
Both the ways providing same result.
Once you created bitmap as I said earlier, use following snippet to send it as attachment.
String path = Images.Media.insertImage(getContentResolver(), your_bitmap, "title", null);
Uri screenshotUri = Uri.parse(path);
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, "Send email using"));
Assets directory is private to your app and is not available to other apps. So sharing directly from assets is not possible. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file. Have a look here.
You can't share the file directly, but should be using a content provider to share it.
To avoid writing your own content provider, see cwac-provider
CWAC-Provider: Helping to Make Content Providers Sane
This project offers a StreamProvider, based on Google's FileProvider. Like FileProvider, StreamProvider is designed to serve up files, for reading and writing, through the ContentProvider interface (content:// Uri values). StreamProvider offers:
Serving files from assets and raw resources
Serving files from getExternalFilesDir() and getExternalCacheDir()
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