title: Android Open Image to Gallery - No Thumbnail Message
body: <p>If I save my image using the below code, and then open my gallery manually, the image displays fine. If I try to open the gallery programmatically, I get a message from the gallery saying "No Thumbnail".</p>
  
  <pre><code>//save bitmap--------------------------------------------------
                  File myDir=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"");
                  myDir.mkdirs();
                  Random generator = new Random();
                  int n = 10000;
                  n = generator.nextInt(n);
                  String fname = "Image-"+ n +".jpg";
                  File file = new File (myDir, fname);
                  if (file.exists ()) file.delete ();
                  try {
                      FileOutputStream out = new FileOutputStream(file);
                      bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
                      out.flush();
                      out.close();
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  //media scan--------------------------------------------------
                  Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                  File f = new File(myDir.getAbsolutePath());
                  Uri contentUri = Uri.fromFile(f);
                  mediaScanIntent.setData(contentUri);
                  this.getApplicationContext().sendBroadcast(mediaScanIntent);
  
                  //view in gallery (here is where my gallery gives "No Thumbnail" message)----
                  Intent viewIntent = new Intent();
                  viewIntent.setAction(Intent.ACTION_VIEW);
                  viewIntent.setDataAndType(Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+""),"image/*");
                  startActivity(viewIntent);
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/yZk9M.jpg" alt="no thumbnail"></p>