dickfala
dickfala

Reputation: 3306

Android How can I using Cursor get image and video thumbnails in my direct path both?

How can I using Cursor get image and video thumbnails in my direct path in same cursor?

I need get the image and video thumbnails in /DCIM/100ANDRO folder.

But I just can separate to get image and video in at sd card all data.

  private ArrayList<ImageItem> getData() {
          final ArrayList<ImageItem> imageItems = new ArrayList<>();

          ContentResolver cr = mContext.getContentResolver();

   String[] projection = {MediaStore.Images.Thumbnails.DATA, MediaStore.Video.Thumbnails.DATA};
          Cursor cursor = cr.query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,projection,null,null,null);

          for( int i = 0 ; i < cursor.getCount(); i++)
          {
              cursor.moveToPosition(i);
              String filePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
              Log.i("info","filePath:"+filePath);
              File file = new File(filePath);

              Bitmap myBitmap =       BitmapFactory.decodeFile(file.getAbsolutePath());

              imageItems.add( new ImageItem(myBitmap, "Image#" + i) );
          }


          cursor =       cr.query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,projection,null,null,null);
          for( int i = 0 ; i < cursor.getCount(); i++)
          {
              cursor.moveToPosition(i);
              String filePath = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
              Log.i("info","filePath:"+filePath);
              File file = new File(filePath);

              Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());

              imageItems.add( new ImageItem(myBitmap, "Image#" + i) );
          }

          cursor.close();
  return imageItems;
      }

Have possible using cursor direct folder to get the thumbnails and get video and image thumbnails both?

thank you very much.

Upvotes: 2

Views: 4702

Answers (1)

dickfala
dickfala

Reputation: 3306

I found the answer.

We should inverse the method.

We can find the real path. then to get the ID.

Through the ID to get the images and videos thumbnails.

To get the images and videos using a cursor can refer the articles.

Getting images thumbnails using below code:

 bitmap = MediaStore.Images.Thumbnails.getThumbnail(context
                        .getApplicationContext().getContentResolver(), item.getImgId(),
                MediaStore.Images.Thumbnails.MICRO_KIND, null);

Getting video thumbnails using below code:

  bitmap = MediaStore.Video.Thumbnails.getThumbnail(context
                       .getApplicationContext().getContentResolver(), item.getImgId(),
               MediaStore.Images.Thumbnails.MICRO_KIND, null);

Upvotes: 1

Related Questions