title: how to share a image bitmap with intent in android?
body: <p><strong>(This question isn't duplicate !)</strong></p>
  
  <p>How can I share an image via intent ?</p>
  
  <p>I tried this </p>
  
  <p><a href="https://stackoverflow.com/a/30172792/10807406"><strong><em>Android Share Intent for a Bitmap - is it possible not to save it prior sharing?</em></strong></a></p>
  
  <p><strong><em><a href="https://stackoverflow.com/questions/35966487/how-to-share-image-to-social-media-with-bitmap">How to share image to social media with bitmap?</a></em></strong></p>
  
  <p><strong><em><a href="https://stackoverflow.com/questions/25135873/share-image-with-url-android-share-intent">share image with URL android share intent</a></em></strong></p>
  
  <p>but only worked on the emulator and did not work on the actual phone and made the following code error:</p>
  
  <pre><code>//b method : convert inputstream to bitmap
  String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), b(inputStream) ,"title", null);
  </code></pre>
  
  <p>Full code : </p>
  
  <pre><code>InputStream is = getAssets().open(imageName.getText().toString());
  int size = is.available();
  byte[] buffer = new byte[size];
  is.read(buffer);
  is.close();
  String path = Environment.getExternalStorageDirectory()+"/" + APP_NAME()+"/pictures/"+ls+"/" ;
  new File(path).mkdirs();
  String fileName = System.currentTimeMillis() + imageName.getText().toString().replace("pic/" , "");
  FileOutputStream fileOutputStream = new FileOutputStream(new File(path+fileName));
  fileOutputStream.write(buffer);
  fileOutputStream.close();
  InputStream inputStream = new FileInputStream(new File(path+fileName));
  
  String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), b(inputStream) ,"title", null);
  Uri bitmapUri = Uri.parse(bitmapPath);
  
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.setType("image/*");
  intent.putExtra(Intent.EXTRA_STREAM , bitmapUri);
  startActivity(intent);
  
  
  //Intent intent = new Intent(android.content.Intent.ACTION_SEND);
  //intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
  //intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  //intent.setType("image/*");
  //startActivity(intent);
  </code></pre>