title: save image in gallery android
body: <p>I am using this code to save the image:</p>
  
  <pre><code>URL url = null;
              try {
                  url = new URL("image");
              } catch (MalformedURLException e1) {
                  e1.printStackTrace();
              }
              Bitmap bmp = null;
              try {
                  bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
              } catch (IOException e1) {
                  e1.printStackTrace();
              }
              OutputStream output;
              File filepath = Environment.getExternalStorageDirectory();
              File dir = new File(filepath.getAbsolutePath() + "/folder name/");
              dir.mkdirs();
              File file = new File(dir, image + ".png");
              Toast.makeText(HomeActivity.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
              try {
  
                  output = new FileOutputStream(file);
                  bmp.compress(Bitmap.CompressFormat.PNG, 100, output);
                  output.flush();
                  output.close();
  
              }
  
              catch (Exception e) {
                  e.printStackTrace();
              }
  </code></pre>
  
  <p>The issue is when this code runs on lollipop devices, Images are not showing in gallery. I have to install File Manager to check these images.</p>
  
  <p>With this code:</p>
  
  <pre><code>    MediaStore.Images.Media.insertImage(getContentResolver(), bmp, "image";
  </code></pre>
  
  <p>Images are saved in camera folder.</p>
  
  <p>I want to show images in gallery with a specific folder name in all android devices.</p>
  
  <p>Please help.</p>