简体   繁体   中英

Not getting all media files which inserted manullay in sd card

I used below query to load all pictures or video from sd card and it works accordingly. But when I add some video or pictures manually into sd card at different folder then its not loading after query. Please suggest me regarding same.

    final String[] columns = { MediaStore.Video.Media.DATA,
                MediaStore.Video.Media._ID};


        final String orderBy = MediaStore.Video.Media.DATE_TAKEN;
        Uri videosuri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;

        Cursor imagecursor = getContentResolver().query(videosuri, columns, null, null, orderBy);


        if (imagecursor != null && imagecursor.getCount() > 0) {

            while (imagecursor.moveToNext()) {

                int video_id=imagecursor.getInt(imagecursor.getColumnIndex(MediaStore.Video.Media._ID));
                int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Video.Media.DATA);
 String path=imagecursor.getString(dataColumnIndex);



            }
        }

When you "add some video or pictures manually into sd card at different folder", the MediaStore has to be updated in order for them to be available to your query, as well as to other apps that use the MediaStore backend.

Adding them via MTP or apps like Gallery will invoke the MediaScanner (or some similar process) to add them to the MediaStore , but adding them via adb push or in your own code requires you to explicitly do so afterward.

In your code, after writing an image or video file to the SDCard, you can pass the path and MIME type of the file to the MediaScanner by implementing the MediaScannerConnectionClient interface in a class, instantiating it, then calling scan() . The MediaScanner will then open the file, collect/generate metadata, and add the file to the MediaStore

See android - dynamically add pictures to gallery widget for an example class using this approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM