[英]Obtaining image from camera intent on Android
I am following the Google tutorial on launching a new intent to take and deliver a photo. 我正在遵循有关如何启动拍摄和传送照片的新意图的Google教程。 https://developer.android.com/training/camera/photobasics .
https://developer.android.com/training/camera/photobasics 。 I am unable to get past a certain spot because I get this exception:
Failed to find configured root that contains /storage/emulated/0/Android/data/com.example.matthew.doodlewits/files/Pictures/JPEG_20190108_220143_4398098916939163453.jpg
我无法越过某个地点,因为遇到了以下异常:
Failed to find configured root that contains /storage/emulated/0/Android/data/com.example.matthew.doodlewits/files/Pictures/JPEG_20190108_220143_4398098916939163453.jpg
The exception happens at 例外发生在
Uri uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", image);
In the below method: 在以下方法中:
private void takePictureSetup()
{
try
{
Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timestamp + "_";
File storageDirectory = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDirectory);
currentPathToPictureTaken = image.getAbsolutePath();
Uri uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, this.RESULT_CAMERA_PHOTO);
}
catch(Exception e)
{
Log.d("**EXCEPTION**", e.getMessage());
}
}
This is the XML file that I have created: 这是我创建的XML文件:
And here is the xml layout code of that file: 这是该文件的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.package.name/files/Pictures" />
</paths>
And finally in my manifest file: 最后在清单文件中:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
The problem is at your provider path 问题出在您的提供者路径上
Your current provider path is 您当前的提供商路径为
Android/data/com.example.package.name/...
It should be 它应该是
Android/data/com.example.matthew.doodlewits/...
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.