在列表视图中显示 SD 卡中特定文件夹中的视频

发布于 2024-12-10 01:59:38 字数 523 浏览 2 评论 0原文

我正在尝试使用 SD 卡上创建的文件夹中的视频文件填充列表视图。我正在使用

managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,mystring, null, null, null);

但它填充了保存在 SD 卡中的所有视频,但我只想要那些保存在特定文件夹中的视频。我也用过

Uri uri = Uri.fromFile(filepath);
cursor = managedQuery(uri, mystring , null , null , null); 

Uri uri = Uri.parse(filepath);
cursor = managedQuery(uri, mystring , null , null , null);

但是不起作用。我已经尝试了很多并得到了谷歌的帮助仍然没有成功。 有什么办法可以给出该文件夹的路径吗?或者任何其他方式?

i am trying to populate listview with video files from a folder created on sd card. I am using

managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,mystring, null, null, null);

But it populates all videos saved in sdcard, but i want only those videos which are saved in specific folder. I have also used

Uri uri = Uri.fromFile(filepath);
cursor = managedQuery(uri, mystring , null , null , null); 

and

Uri uri = Uri.parse(filepath);
cursor = managedQuery(uri, mystring , null , null , null);

But it doesn't work. I have tried lot and got help from google still not succeded.
Is there any way to give path of that folder? or any other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╭⌒浅淡时光〆 2024-12-17 01:59:38

您可以使用此代码从特定文件夹获取视频,如下所示:

String selection=MediaStore.Video.Media.DATA +" like?";
        String[] selectionArgs=new String[]{"%FolderName%"};
        videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                parameters, selection, selectionArgs, MediaStore.Video.Media.DATE_TAKEN + " DESC");

you can use this code for get videos from specific folder as:

String selection=MediaStore.Video.Media.DATA +" like?";
        String[] selectionArgs=new String[]{"%FolderName%"};
        videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                parameters, selection, selectionArgs, MediaStore.Video.Media.DATE_TAKEN + " DESC");
非要怀念 2024-12-17 01:59:38

您可以像这样从特定位置获取文件

item = new ArrayList<String>();
 path = new ArrayList<String>();

 File f = new File("/sdcard/");

 // or you can use File f=new File(Environment.getExternalStorageDirectory().getPAth());
 File[] files = f.listFiles();


 for(int i=0; i < files.length; i++)
 {
   File file = files[i];
   path.add(file.getPath());
   if(file.isDirectory())
    item.add(file.getName() + "/");
   else
    item.add(file.getName());
 }

 ArrayAdapter<String> fileList =
  new ArrayAdapter<String>(this, R.layout.row, item);
 setListAdapter(fileList);

You can get a files form a specific location like this

item = new ArrayList<String>();
 path = new ArrayList<String>();

 File f = new File("/sdcard/");

 // or you can use File f=new File(Environment.getExternalStorageDirectory().getPAth());
 File[] files = f.listFiles();


 for(int i=0; i < files.length; i++)
 {
   File file = files[i];
   path.add(file.getPath());
   if(file.isDirectory())
    item.add(file.getName() + "/");
   else
    item.add(file.getName());
 }

 ArrayAdapter<String> fileList =
  new ArrayAdapter<String>(this, R.layout.row, item);
 setListAdapter(fileList);
開玄 2024-12-17 01:59:38

嘿 ManagedQuery 搜索整个 SD 卡而不是特定文件夹。
上面的方法对于显示文件名是正确的,但是如果您要显示缩略图,则创建缩略图并将其存储在 Hashmap 中并将其填充到图库适配器列表中..............

hey managedquery search the whole sdcard not the specific folder .
the above method is true of display the name of file but if you to display thumbnail create thumbmail and store in in Hashmap and populate it to the list of gallery adapter..........

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文