Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中获取私人文件夹的Uri?_Android_Cursor_Uri_Image Gallery_Photo Gallery - Fatal编程技术网

如何在Android中获取私人文件夹的Uri?

如何在Android中获取私人文件夹的Uri?,android,cursor,uri,image-gallery,photo-gallery,Android,Cursor,Uri,Image Gallery,Photo Gallery,我正在尝试制作一个带有图像库的android摄像头应用程序。捕获的图像保存到一个私有目录:Android/data/com.example.newcamera/files/pictures 每当我使用内部内容URI或外部内容URI作为URI时,应用程序都会带来我手机的所有公共图片,但不会带来私人目录中的图片。但是我只需要那些有私有目录的。我怎样才能得到它?请帮帮我。我的代码片段如下所示: 提前谢谢 protected String doInBackground(String... arg

我正在尝试制作一个带有图像库的android摄像头应用程序。捕获的图像保存到一个私有目录:Android/data/com.example.newcamera/files/pictures

每当我使用内部内容URI或外部内容URI作为URI时,应用程序都会带来我手机的所有公共图片,但不会带来私人目录中的图片。但是我只需要那些有私有目录的。我怎样才能得到它?请帮帮我。我的代码片段如下所示:

提前谢谢

    protected String doInBackground(String... args) {
        String xml = "";

        String path = null;
        String album = null;
        String timestamp = null;
        String countPhoto = null;
        Uri uriInternal = MediaStore.Images.Media.INTERNAL_CONTENT_URI;
        Uri uriExternal = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        Uri myUri = Uri.fromFile(new File(getApplicationContext().getFilesDir().getAbsolutePath()));


        String[] projection = { MediaStore.MediaColumns.DATA,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.MediaColumns.DATE_MODIFIED };
        Cursor cursorExternal = getContentResolver().query(uriExternal, projection, "_data IS NOT NULL) GROUP BY (bucket_display_name",
                null, null);
        Cursor cursorInternal = getContentResolver().query(uriInternal, projection, "_data IS NOT NULL) GROUP BY (bucket_display_name",
                null, null);
        Cursor myCursor = getContentResolver().query(myUri, projection, "_data IS NOT NULL) GROUP BY (bucket_display_name",
                null, null);

        Cursor cursor = new MergeCursor(new Cursor[]{cursorExternal, cursorInternal, myCursor});

        while (cursor.moveToNext()) {

            path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA));
            album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
            timestamp = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED));
            countPhoto = Function.getCount(getApplicationContext(), album);

            albumList.add(Function.mappingInbox(album, path, timestamp, Function.converToTime(timestamp), countPhoto));
        }
        cursor.close();
        Collections.sort(albumList, new MapComparator(Function.KEY_TIMESTAMP, "dsc")); // Arranging photo album by timestamp decending
        return xml;
    }

您可以通过以下方式从特定文件夹获取文件:

File folder = new File(Environment.getExternalStorageDirectory().toString() + "/Folder Name/");
folder.mkdirs();
File[] allFiles = folder.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png"));
    }
});

您可以通过
Uri将文件路径转换为Uri。fromFile(您的文件)

您需要只获取Uri还是知道Uri并希望获取该目录的内容?我需要Uri以及图像库目录的内容。@托马斯·贾布朗斯基。现在请查看我编辑的代码。我正在尝试使用Uri从getContentResolver()获取游标。然后,我使用了一些其他函数从光标获取路径,以创建我的图像库。我的全部代码都是基于这个片段的。在这种情况下,我将从应用程序的私有目录中获取除图像以外的所有图像。你能帮我一下吗。我不知道我的代码出了什么问题。