Android sharing the activity image using a button - android

I want the image that the user made to be shared when he clicks on the button
the image is an image he made using many features like paint etc ..
I want when he clicks on the sharing button a sharing intent "share via."
appears and let him choose where he wants it to be shared at
I found this code but I get an error from (path)
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
How can I do this?

What do you put in the variable path?
Path is the route to the file where you have saved the bitmap previously (sdcard or internal app storage).
It's right that the picture must be saved first, but If you are not saving it now, how do you fill path variable?

Related

how to share files with Share Provider in android programmatically

I want to share image on share button click, but in my code not working properly,
shareBtn.setOnClickListener(view -> {
Uri uri = Uri.parse(mImagePath);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Image"));
});
in my app, I fetching images from gallery, showing in app while sharing image this code working,
How should I share image from my app to another?

Share image puts path in to address

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

share image intent image is an actually url of image not an application resource

Actually I am getting all rss feed from here
Now I all complete with my code But I want to add one functionality of share image.
Now I have image linke for ex.
http://miscmedia-9gag-lol.9cache.com/images/long-post-cover/12796580_1414746906.7976_Ejy2yj_460c.jpg link
How can I share this image like sharing an regular image.
I solved such issue by downloading image before sharing. (If you display images in your app using library like universal image loader or implemented such functionality on your own the only thing you need to do is to find predownloaded image on file system) If image is not large it will not take much time to download. Then you can delete image file after sharing.
try this,
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageurl);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to..");

Share file via Intent is Ok even if the file type don't match

I use the following code to share a image, it's Ok if the image type is png.
But I'm very surprised that it's still OK if the the image type is jpeg. Why? Thanks!
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file://"+arrPath[i]);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
This is how the Intent system works.
http://developer.android.com/guide/components/intents-filters.html#iobjs
An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity).
The responsibility of actually dealing with the file is left with the applications that register to handle that kind of intent. At this stage it's not going to care/check whether the file is a jpg or a png.
You're basically saying "hey, sharing applications! I have a png for you!"
I'm not sure what exactly you are after but if you don't want jpgs to be shared you need to handle that in your code.

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.

Categories

Resources