Uri.parse("file://" + ???);访问特定的文件夹

编程入门 行业动态 更新时间:2024-10-28 08:21:29
本文介绍了Uri.parse("file://" + ???);访问特定的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题是两部分,我如何获得以下代码来访问此位置: "/storage/emulated/0/Movies/SpecificFolder"

My question is two part, how can I get the following code to access this location: "/storage/emulated/0/Movies/SpecificFolder"

代码:

private Uri getUriFromMediaStore(int position) { int dataIndex = mMediaStoreCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA); mMediaStoreCursor.moveToPosition(position); String dataString = mMediaStoreCursor.getString(dataIndex); Uri mediaUri = Uri.parse("file://" + dataString); return mediaUri; }

,当时间到来时,如何从在线服务器访问视频/文件?

and, when the time comes how can I access videos/files from an online server?

我尝试了以下操作:

mediaCursor = getContentResolver().query( MediaStore.Files.getContentUri("external"), null, MediaStore.Images.Media.DATA + " like ? ", new String[] {"%YOUR_FOLDER_NAME%"}, null);

但是,只有在我的类继承了"Activity",而我却从以下类继承时,才可以使用getContentResolver():

BUT, getContentResolver() can only be used if my class extends "Activity" which it does not, I am inheriting from:

RecyclerView.Adapter<MediaStoreAdapter.ViewHolder>

并且Java不允许双重继承.

and Java does not allow double inheritance.

推荐答案

我误解了代码的哪一部分需要编辑才能访问特定的文件夹.我正在尝试编辑代码部分,其中光标显示其选择/接收的缩略图,而当要做的是限制光标从哪里使用SQLite获取图像/视频时.

I was mistaken in which section of the code needed editing to access a specific folder. I was trying to edit the section of code where the cursor shows the thumbnails it has chosen/received, when what needs to be done is to limit where the cursor is getting the images/videos from using SQLite.

最初遵循本教程: www.youtube/watch?v= R23RBPkO8BY& list = PL9jCwTXYWjDJ6o1uabT54z1YmYYBh9US6& index = 6

在Nigel Henshaw对Codementor的帮助下,他能够提供此解决方案,并希望我分享: www.codementor.io/mobapptuts

And with Nigel Henshaw's help on Codementors, he was able to provide this solution and wanted me to share: www.codementor.io/mobapptuts

在MainActivity中,我们首先设置了游标:

In MainActivity, where we first set up the Cursor:

public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] projection = { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATE_ADDED, MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.MEDIA_TYPE }; String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO + MediaStore.Video.Media.DATA; return new CursorLoader( this.getContext(), MediaStore.Files.getContentUri("external"), projection, selection, null, MediaStore.Files.FileColumns.DATE_ADDED + " DESC" ); }

用于指定单个文件夹的代码:

The code to specify an individual folder:

public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] projection = { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATE_ADDED, MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.MEDIA_TYPE }; String selection = "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " AND " + MediaStore.Images.Media.DATA + " LIKE ? )" + " OR " + "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO + " AND " + MediaStore.Video.Media.DATA + " LIKE ? )"; String [] selectionArgs = new String[] {"%SpecificFolder%", "%SpecificFolder%"}; return new CursorLoader( this.getContext(), MediaStore.Files.getContentUri("external"), projection, selection, selectionArgs, MediaStore.Files.FileColumns.DATE_ADDED + " DESC" ); }

此解决方案可处理您文件夹中的图像和视频.

This solution handles both Images and Videos in your folder.

更多推荐

Uri.parse("file://" + ???);访问特定的文件夹

本文发布于:2023-10-31 16:50:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546694.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   parse   Uri   file   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!