gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:52:15 27 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





how to fix an authority error in android studio

(2 个回答)



Couldn't find meta-data for provider with authority

(16 个答案)


2年前关闭。




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

Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal. 

我留下了我的应用程序的名称,所以每个人都可以看到我也在 list 中更改了它。

显现:
<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" />

文件路径.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>

以及我使用它的代码:
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;
}

最佳答案

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

Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal.



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

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

顺便说一句,最好遵循 Java 指南,以 PascalCase 格式命名您的类。

例如:
  • FileProvider对比 fileprovider
  • MainActivity对比 mainActivity

  • 等等

    关于android - 找不到提供程序错误的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59354185/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com