找不到提供程序错误的元数据

Cos*_*tin 2 android

我正在尝试开发一个可以拍照的应用程序,然后将它们上传到数据库。现在我坚持拍摄高质量的照片。正如我之前读到的,要获得质量更好的照片,您需要将其保存在您的目录中。我正在遵循 开发人员说明中的Google Take Photos,在添加了所有方法和提供程序等之后,我收到错误消息:

Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal. 
Run Code Online (Sandbox Code Playgroud)

我已经留下了我的应用程序的名称,以便每个人都可以看到我也在清单中更改了它。

显现:

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.example.navigationdrawerfinal.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />
Run Code Online (Sandbox Code Playgroud)

file_paths.xml :

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="my_images" path="Android/data/com.example.navigationdrawerfinal/files/Pictures" />
</paths>
Run Code Online (Sandbox Code Playgroud)

以及我使用它的代码:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    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
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.navigationdrawerfinal",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            poza_neincarcata.setVisibility(View.GONE);
            poza_tick.setVisibility(View.VISIBLE);
        }
    }
}


private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
        currentPhotoPath = image.getAbsolutePath();
        return image;
    }
Run Code Online (Sandbox Code Playgroud)

Edr*_*ric 6

如错误所示(重点是我的):

无法找到具有com.example.navigationdrawerfinal权限的提供者的元数据。

这是因为您FileProviderphotoURI定义的变量指定了不正确的需要- 它应该与FileProvider您在清单文件中定义的完全相同,区分大小写:

Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.navigationdrawerfinal.fileprovider", // Over here
                    photoFile);
Run Code Online (Sandbox Code Playgroud)

顺便说一下,通过以 PascalCase 格式命名您的类来遵循 Java 指南是个好主意。

例如:

  • FileProvider 对比 fileprovider
  • MainActivity 对比 mainActivity

等等。