简体   繁体   English

在Android Studio中获取相机胶卷

[英]Get camera roll in Android Studio

I'm trying to create an auto-backup app in which all photos taken from the Camera will be uploaded to Cloudinary. 我正在尝试创建一个auto-backup应用程序,其中将从Camera拍摄的所有照片都将上传到Cloudinary。 However, I cannot seem to get my code working. 但是,我似乎无法使我的代码正常工作。 What am I doing wrong? 我究竟做错了什么?

    class UploadPhotos implements Runnable {

        @Override
        public void run() {
            File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
            File[] listOfFiles = storageDir.listFiles();

            if (listOfFiles != null) {
                System.out.println("code does not get this far");
                for (int i = 0; i < listOfFiles.length; i++) {
                    if (listOfFiles[i].isFile()) {
                        System.out.println("File " + listOfFiles[i].getName());
                        try {
                            cloudinary.uploader().upload(listOfFiles[i], ObjectUtils.emptyMap());
                            System.out.print(listOfFiles[i] + " should have uploaded");
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                    } else if (listOfFiles[i].isDirectory()) {
                        System.out.println("Directory " + listOfFiles[i].getName());
                    }
                }
            }
        }
    }

The storageDir path comes out as /storage/0804-0A1C/DCIM within the Android Studio emulator but listOfFiles is null (despite having taken several pictures with the Camera). Android Studio emulatorstorageDir路径显示为/storage/0804-0A1C/DCIM ,但listOfFiles为空(尽管使用Camera拍摄了几张照片)。

Using Android Device Monitor, I found that the storage location for Camera images in my Android Studio is "/storage/0804-0A1C/DCIM/Camera". 使用Android设备监视器,我发现Android Studio中“相机”图像的存储位置为“ / storage / 0804-0A1C / DCIM / Camera”。

However, I am unable to read from this directory despite recursive checks (because of permissions?). 但是,尽管进行了递归检查(由于权限?),但我仍无法从该目录读取。 To avoid going off-topic, I've posted a new question linked below: 为了避免出现话题,我在下面发布了一个新问题链接:

Camera storage perms in Android Studio Android Studio中的相机存储权限

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

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