How to Use "Share Image Using" Sharing Intent to Share Images in Android

Share image with action send

Try this

Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));

How to Share Image+Text using Share Intent in android

Try out the below code:

String fileName = "image-3116.jpg";//Name of an image
String externalStorageDirectory = Environment.getExternalStorageDirectory().toString();
String myDir = externalStorageDirectory + "/saved_images/"; // the file will be in saved_images
Uri uri = Uri.parse("file:///" + myDir + fileName);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test Mail");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Launcher");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share Deal"));

Share image with Android intent

First, there is no guarantee that any given other app will be able to support an android:resource// Uri. You will have greater compatibility sharing a file on external storage or using a ContentProvider.

That being said, replace:

File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString());
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));

with:

    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share);

An android:resource:// is not a File, and probably you are messing up your Uri by converting to a File and then back to a Uri.

share image with URL android share intent

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

How can i send image with text with share

YOu have to save the bitmap from url into the disk first then use the file to be passed on intent.

    File file = writebitmaptofilefirst("the_new_image","http://www.theimagesource.com/blahblahblah.jpg");
Uri uri = Uri.fromFile(file);

shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

Add this method

public static File writebitmaptofilefirst(String filename, String source) {
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File mFolder = new File(extStorageDirectory + "/temp_images");
if (!mFolder.exists()) {
mFolder.mkdir();
}
OutputStream outStream = null;


File file = new File(mFolder.getAbsolutePath(), filename + ".png");
if (file.exists()) {
file.delete();
file = new File(extStorageDirectory, filename + ".png");
Log.e("file exist", "" + file + ",Bitmap= " + filename);
}
try {
URL url = new URL(source);
Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());

outStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Log.e("file", "" + file);
return file;

}


Related Topics



Leave a reply



Submit