我正在使用一种简单的方法从Camera捕获图像,但是此时我收到以下错误报告:
Uri photoURI = FileProvider.getUriForFile(ReceiptActivity.this, "com.example.ves.gennaio3.fileprovider", pictureFile);
根据我的说法,它与使用的权限有关,但在清单中似乎是正确的。
AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.ves.gennaio3.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
android:readPermission="com.company.app.fileprovider.READ">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_list" />
</provider>
res / xml / file_list.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="my_images" path="my_images" />
</paths>
Java
public void captureImage(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
pictureFile = Helper.getPictureFile(ReceiptActivity.this);
if (pictureFile != null) {
Uri photoURI = FileProvider.getUriForFile(ReceiptActivity.this, "com.example.ves.gennaio3.fileprovider", pictureFile); //error here
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(cameraIntent, REQUEST_PICTURE_CAPTURE);
}
}
}
Logcat
> 04-23 17:44:38.456 27102-27102/com.example.ves.gennaio3
> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.example.ves.gennaio3, PID: 27102
> java.lang.IllegalStateException: Could not execute method for android:onClick
> at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
> at android.view.View.performClick(View.java:5201)
> at android.view.View$PerformClick.run(View.java:21163)
> at android.os.Handler.handleCallback(Handler.java:746)
> at android.os.Handler.dispatchMessage(Handler.java:95)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> Caused by: java.lang.reflect.InvocationTargetException
> at java.lang.reflect.Method.invoke(Native Method)
> at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
> at android.view.View.performClick(View.java:5201)
> at android.view.View$PerformClick.run(View.java:21163)
> at android.os.Handler.handleCallback(Handler.java:746)
> at android.os.Handler.dispatchMessage(Handler.java:95)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains
> /storage/emulated/0/Android/data/com.example.ves.gennaio3/files/Pictures/OCR_20190423174438-702062338.jpg
> at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:738)
> at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
> at com.example.ves.gennaio3.ReceiptActivity.captureImage(ReceiptActivity.java:173)
> at java.lang.reflect.Method.invoke(Native Method)
> at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
> at android.view.View.performClick(View.java:5201)
> at android.view.View$PerformClick.run(View.java:21163)
> at android.os.Handler.handleCallback(Handler.java:746)
> at android.os.Handler.dispatchMessage(Handler.java:95)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
PS。我曾尝试提出一个苗条的问题,但看起来我的帖子大部分是代码,所以我添加了其他无用的文字以使其可发布。