0

A doubt. How can I share an imageview that is being displayed on the screen?

Here's an App Example: http://www.mediafire.com/convkey/d5a3/l0b5eobtpdbeoenzg.jpg

Every time a new image is clicked on the image, the resource used was an array that looks for the ID's in the Drawable folder.

Thank You!!!

Tisco
  • 53
  • 9

1 Answers1

1
Try this...Don't forget to give write storage permission in manifest 
and run time for API greater than marshmallow.
Bitmap bitmap= 
BitmapFactory.decodeResource(getResources(),R.drawable.xxxx);
String path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)+"/LatestShare.jpg";
OutputStream out = null;
File file=new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path=file.getPath();
Uri bmpUri = Uri.parse("file://"+path);
 Intent shareIntent = new Intent();
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent,"Share with"));
Malika
  • 74
  • 3
  • Thanks for the reply Malika. I pointed to my array, but when sharing does not pull the image, it is black background and is informed that there was a failure to share. Besides the path R.drawable.xxxx have to change something else in the code? Thank you. – Tisco May 09 '17 at 23:40
  • Try this to edit in above answer : TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs); Bitmap bitmap= BitmapFactory.decodeResource(getResources(),imgs.getResourceId(i, -1)); i is your clicked array position and -1 is default value. – Malika May 10 '17 at 15:18
  • Malika, thanks again for the help. He calls the intention, but does not appear the image, still remains with the black background. I emulate the direct application on my device that has the Cyanogen system, can this influence the result? Because I've tried different solutions and none of them worked for me. Can it be my device? Thank you so much. – Tisco May 10 '17 at 19:40
  • Do this changes: ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try { out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); out.write(bytes.toByteArray()); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace();} and change format of saved image jpg to png. – Malika May 10 '17 at 20:26