title: How to display video thumbnails in android
body: <p>I am trying to show a thumbnail for my video. I store my video in my directory, but I get an error in my log cat <code>NO THUMB NAIL</code>. Can anyone  help me how to solve this? Another thing is that when I run my app on a MOTO G device it shows an image name, but when I tested the same app on a nexus device it shows no files here. </p>
  
  <pre><code>public class Vedigridview extends AppCompatActivity {
  
      private static final String MEDIA_PATH = new String(
              Environment.getExternalStorageDirectory().toString()+"/pawan_app");
  
      String[] fileList = null;
      GridView gridView;
      String FILE_PATH = Environment.getExternalStorageDirectory().toString()+"/pawan_app";
      String MiME_TYPE = "video/mp4";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_vedigridview);
  
          updateSongList();
          gridView = (GridView) findViewById(R.id.gridView1);
          if (fileList != null) {
              gridView.setAdapter(new ImageAdapter(this, fileList));
          }
          gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                                      int position, long id) {
                  Toast.makeText(
                          getApplicationContext(),
                          ((TextView) v.findViewById(R.id.grid_item_label))
                                  .getText(), Toast.LENGTH_SHORT).show();
                  String videoFilePath = FILE_PATH + fileList[position];
                  System.out
                          .println("******************************videoFilePath****************"
                                  + videoFilePath);
  
                  System.out
                          .println("******************************MiME_TYPE****************"
                                  + MiME_TYPE);
                  Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
                  File newFile = new File(videoFilePath);
                  intent.setDataAndType(Uri.fromFile(newFile), MiME_TYPE);
                  startActivity(intent);
              }
          });
  
      }
      public void updateSongList() {
          File videoFiles = new File(MEDIA_PATH);
          Log.d("*********Value of videoFiles******", videoFiles.toString());
  
          if (videoFiles.isDirectory()) {
              fileList = videoFiles.list();
          }
          if (fileList == null) {
              System.out.println("File doesnot exit");
              Toast.makeText(this, "There is no file", Toast.LENGTH_SHORT).show();
          } else {
              System.out.println("fileList****************" + fileList);
              for (int i = 0; i &lt; fileList.length; i++) {
                  Log.e("Video:" + i + " File name", fileList[i]);
  
              }
          }
  
      }
  
      public class ImageAdapter extends BaseAdapter {
          private Context context;
  
          private final String[] VideoValues;
  
          public ImageAdapter(Context context, String[] VideoValues) {
              this.context = context;
              this.VideoValues = VideoValues;
          }
  
          public View getView(int position, View convertView, ViewGroup parent) {
              System.out.println("***********IngetView************");
              LayoutInflater inflater = (LayoutInflater) context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
              View gridView;
  
              if (convertView == null) {
  
                  gridView = new View(context);
  
                  // get layout from gridlayout.xml
                  gridView = inflater.inflate(R.layout.gridlayut, null);
  
                  // set value into textview
                  TextView textView = (TextView) gridView
                          .findViewById(R.id.grid_item_label);
                  textView.setText(fileList[position]);
                  System.out.println("value of fileList[position]" + fileList[0]);
                  // set image
                  ImageView imageThumbnail = (ImageView) gridView
                          .findViewById(R.id.grid_item_image);
  
                  Bitmap bmThumbnail;
  
                  System.out
                          .println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; file path&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"
                                  + fileList[position]);
  
                  bmThumbnail = ThumbnailUtils.createVideoThumbnail(FILE_PATH
                                  + fileList[position],
                          MediaStore.Video.Thumbnails.MINI_KIND);
  
  
  
                  if (bmThumbnail != null) {
                      System.out
                              .println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; THUMB NAIL&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;");
  
                      imageThumbnail.setImageBitmap(bmThumbnail);
                  } else {
                      System.out
                              .println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;NO THUMB NAIL&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;");
  
                  }
  
              } else {
                  gridView = (View) convertView;
              }
  
              return gridView;
          }
  
          public int getCount() {
              // return 0;
              return VideoValues.length;
          }
  
          public Object getItem(int position) {
              return null;
          }
  
          public long getItemId(int position) {
              return 0;
          }
  
      }
  
  }
  </code></pre>
  
  <p>Here my error in my logcat: </p>
  
  <pre><code>01-31 18:06:41.997 3776-3776/com.foldervedoi.videofolder I/System.out: &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;NO THUMB NAIL&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  </code></pre>