Android: Share Bitmap not saved for SD

I have an application that takes a screenshot and shares it with the intention of sharing. Instead of saving multiple images every time the user just wants to share the image. Below is the code I used for images stored on SD

Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/png"); dir = "file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Folder/" + location; share.putExtra(Intent.EXTRA_STREAM, Uri.parse(dir)); startActivity(Intent.createChooser(share, "Share Image")); 

However, I cannot figure out how easy it is to save a bitmap, for example ...

 share.putExtra(Intent.EXTRA_STREAM, theBitmap); 

Is there any way to do this without saving the image?

thanks

+6
source share
3 answers

What I did was save one “Temp” image to SD / Phone and just overwrite it every time.

+4
source

Try using this:

 Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); Uri uri = Uri.parse("android.resource://com.your.app/drawable/" + yourimage); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_TEXT, shareImage); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, "Send your image")); 

This code is great for sending shortcuts that I use in my application. Photos are not saved on the SD card. The only problem is that it does not work with some social applications: /

+1
source

Yes, you can send an image without saving it as a file. From simply viewing the code you sent, I have no idea how to send the image, but you are converting a file with the following:

  ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] data; if(yourBitmap!=null){ yourBitmap.compress(CompressFormat.PNG, 75, bos); }else if (yourBitmap==null){ Log.w("Image going to server is null","Lost in memory"); } try{ data = bos.toByteArray(); 

I don’t know if you are sending the image to another user through your application or what, but the way I use it to upload to the server. When you are done with the image, you simply invalidate all this.

  bos = null; data = null; yourBitmap = null; 
-1
source

Source: https://habr.com/ru/post/906935/


All Articles