How to save and share bitmap in android

I have activity with image and share button, image obtained from DB

I want to save the image first and then share it

everything is going well, the image is saved in the internal memory and it is going to share, but when another application is launched (for example, whatsapp or messaging), it says that the file does not support

I have another image for ddms manually, and then sharing works without problems! Oo

I think the problem is saving the bitmap, even I checked the saved bitmap from ddms and it looked good

there are my codes:

save

  try {
        FileOutputStream out = new FileOutputStream(new File(getFilesDir(), "temp.png"));
        imageview.setImageBitmap(b1);
        b1.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
       }
       catch (Exception e) {}

general method

  private void initShareIntent(String type,String _text)
  {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(getFilesDir(), "temp.png")));
        shareIntent.setType("image/PNG");
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(shareIntent, "send"));
  }
+3
source share
1 answer

shareIntent.setType("image/*");

shareIntent.setType("image/png");

, . , !

[EDIT1] png ( PNG), , .

[EDIT2] ( GOOGLE: P)

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

All Articles