Nougat getUriForFile 相机问题 Return

Nougat getUriForFile issue with camera Return

我一直在尝试将我的应用程序更新为 Nougat 在意图中处理 URI 的方式,但我这辈子都想不出如何让相机再次工作。我试过按照文档进行操作,但我一定遗漏了一些东西。有人可以帮忙吗?

这是我的调度事件

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            return;
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                   "com.everywhere_ww.provider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }

这是我在清单中的供应商:

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.everywhere_ww.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"/>
    </provider>

这是我的文件路径

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="imgFolder" path="pictures" />
<external-path name="tempFolder" path="temp" />

尝试拍照总是失败

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.everywhere_ww/files/temp/JPEG_20170223_101548_1550424251.jpg

/data/data/com.everywhere_ww/files/temp/JPEG_20170223_101548_1550424251.jpg 似乎是指向 internal storage 的路径。您大概是通过 getFilesDir() 创建的。

替换:

<external-path name="tempFolder" path="temp" />

与:

<files-path name="tempFolder" path="temp" />

您好,不确定是否会有所不同,但请尝试将以下参数添加到您的 xml 文件路径中

<external-path name="external_files" path="."/>