简体   繁体   English

无法获取在SD卡中插入了Manullay的所有媒体文件

[英]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. 我在下面的查询中使用了SD卡中的所有图片或视频,并且可以正常工作。 But when I add some video or pictures manually into sd card at different folder then its not loading after query. 但是,当我手动将一些视频或图片添加到SD卡的其他文件夹中时,查询后无法加载。 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. 当您“将一些视频或图片手动添加到其他文件夹中的sd卡中”时,必须更新MediaStore ,以使它们可用于您的查询以及使用MediaStore后端的其他应用程序。

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. 通过MTP或诸如Gallery之类的应用程序添加它们将调用MediaScanner (或类似的过程)将它们添加到MediaStore ,但是通过adb push或在您自己的代码中添加它们要求您随后明确地这样做。

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() . 在代码中,将图像或视频文件写入SDCard之后,可以通过在类中实现MediaScannerConnectionClient接口,实例化它,然后调用scan() ,将文件的路径和MIME类型传递给MediaScanner The MediaScanner will then open the file, collect/generate metadata, and add the file to the MediaStore 然后, MediaScanner将打开文件,收集/生成元数据,然后将文件添加到MediaStore

See android - dynamically add pictures to gallery widget for an example class using this approach. 请参阅android-使用此方法将图片动态添加到图库小部件中的示例类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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