Skip to content Skip to sidebar Skip to footer

Share Images From Gallery In Android

i have written a program which has two buttons , one is for gallery which when clicked displays my images from gallery and another button which starts my camera which displays the

Solution 1:

These are called intents, some application are listening for contents like images and plain text. when you call these intent, a dialog will open of those applications are listening for your content.

Share single Image

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

Share multiple Image

ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(imageUri1); // Add your image URIs here
imageUris.add(imageUri2);

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.."));

Get ImageURI

public Uri getImageUri(Context inContext, Bitmap inImage) {
  ByteArrayOutputStreambytes=newByteArrayOutputStream();
  inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
  Stringpath= Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
  return Uri.parse(path);
}

OR

Uri.parse(newFile("/sdcard/yourImage.jpg").toString())

More you can here on Android official website

Post a Comment for "Share Images From Gallery In Android"