Android 不能';找不到提供程序错误的元数据
我正在尝试开发一个可以拍照的应用程序,然后再上传到数据库。现在我对拍一张高质量的照片很感兴趣。正如我之前所读到的,为了获得更好的照片质量,您需要将其保存在您的目录中。我正在跟踪 根据开发人员的说明,在添加所有方法和提供程序等之后,我得到了错误:Android 不能';找不到提供程序错误的元数据,android,Android,我正在尝试开发一个可以拍照的应用程序,然后再上传到数据库。现在我对拍一张高质量的照片很感兴趣。正如我之前所读到的,为了获得更好的照片质量,您需要将其保存在您的目录中。我正在跟踪 根据开发人员的说明,在添加所有方法和提供程序等之后,我得到了错误: Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal. 我留下了我的应用程序的名称,这样每个人都可以看到我也在清单中更改了它 舱单:
Couldn't find meta-data for provider with authority com.example.navigationdrawerfinal.
我留下了我的应用程序的名称,这样每个人都可以看到我也在清单中更改了它
舱单:
<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" />
如错误所示(重点是我的):
找不到权限为com.example.navigationdrawerfinal的提供程序的元数据
这是因为您为所定义的photoURI
变量指定了不正确的FileProvider
,它应该与清单文件中定义的FileProvider
完全相同,区分大小写:
Uri photoURI=FileProvider.getUriForFile(这个,
“com.example.navigationdrawerfinal.fileprovider”//在这里
照片文件);
顺便说一句,遵循Java指南,以PascalCase格式命名类是一个好主意 例如:
vsFileProvider
FileProvider
vsMainActivity
MainActivity
等等。在我们的清单中,变化如下
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
您已将清单中的权限指定为com.example.navigationdrawerfinal.fileprovider
,但fileprovider.getUriForFile()
调用正在使用com.example.navigationdrawerfinal
。那些不匹配。是的@MikeM。这是我没有看到的错误。它正在工作,谢谢!再加上一杯咖啡。我不知道为什么人们不使用这个简单而精彩的命名约定。。。
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;
}
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>