【发布时间】:2019-12-16 09:56:02
【问题描述】:
我正在尝试开发一个应用程序来拍摄照片,然后将它们上传到数据库。现在我被困在拍一张高质量的照片上。正如我之前读到的,要获得更好质量的照片,您需要将其保存在目录中。我正在关注Google Take Photos 根据开发人员的说明,添加所有方法和提供程序等后,我收到错误:
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" />
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>
以及我使用它的代码:
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;
}
【问题讨论】:
-
您在清单中将权限指定为
com.example.navigationdrawerfinal.fileprovider,但FileProvider.getUriForFile()调用使用的是com.example.navigationdrawerfinal。那些不匹配。 -
是的@MikeM。那是我没有看到的错误。现在可以使用了,谢谢!
标签: android