这可能是我在编写路径时的愚蠢,但这是我的代码,它无法找到配置的根目录。getUriForFile 是导致错误的原因。
@Override
public void onClick(View v) {
if (v.getId() == R.id.main_activity_camera_access_button) {
Log.d(TAG, "clicked");
Toast.makeText(getContext(), R.string.first_activity_toast_opening_camera, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(intent.resolveActivity(getActivity().getPackageManager()) != null) {
mPhotoFile = null;
try {
mPhotoFile = createImageFile();
} catch (IOException ex) {
Log.d(TAG, "exception while creating photo file");
}
if(mPhotoFile != null){
mfileUri = FileProvider.getUriForFile(getContext(), "edu.lclark.imagineyourwall.fileprovider", mPhotoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mfileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
//mfileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
}
}
我在 res 下有一个 xml 目录,其中有我的 my_paths.xml。这是 my_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/edu.lclark.imagineyourwall.name/files/Pictures" />
</paths>
另外,我的清单看起来像这样,至少是提供者部分。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="edu.lclark.imagineyourwall.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/my_paths"></meta-data>
</provider>