权限拒绝:编写android.support.v4.content.FileProvider uri [英] Permission Denial: writing android.support.v4.content.FileProvider uri

查看:111
本文介绍了权限拒绝:编写android.support.v4.content.FileProvider uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好.我有一个奇怪的问题,堆栈溢出中的所有示例均未解决.我正在打开一个图片库,此后我将用户重定向到裁剪意图.重要的一点是,这仅在android N上发生,而在Android N上不发生问题是一旦完成作物就会引发此异常..我不知道是什么原因造成的,但实际上这是我如何开始作物意图的.

Good day.I have an weird issue to which none of examples in stack overflow has worked.I am opening an gallery,after which i am redirecting user to crop intent.Important to mention that this only happens on android N and not below devices.The issue is that this exception is thrown as soon as the crop is done..I dont know what causes this,but actually here is how i start crop intent.

 Intent cropIntent = new Intent("com.android.camera.action.CROP");
    cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);


    Uri outPutUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", new File(output));
    Uri photoURI = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", new File(path));

    activity.grantUriPermission("com.android.camera.action.CROP", outPutUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    activity.grantUriPermission("com.android.camera.action.CROP", photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);

    cropIntent.setDataAndType(photoURI, "image/*");

    cropIntent.putExtra("crop", "true");

    cropIntent.putExtra("aspectX", aspectX);
    cropIntent.putExtra("aspectY", aspectY);


    cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, outPutUri);

    activity.startActivityForResult(cropIntent, CROP_REQUEST);

我已授予Uri权限,并将其添加到清单中

I have granted the Uri permission,have added these to manifest

  <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>

我已经尝试了所有的堆栈溢出答案示例,在这种情况下,堆栈溢出不再有问题,并且它们中的任何一个都没有起作用.那么android N的问题是什么?难道这么难吗?

I have tried all stack over flow answer examples,there is no more issue on stack overflow with this scenario and not any of them have worked.So what is the issue with android N ?Should it be so hard?

这是抛出的异常

FATAL EXCEPTION: main
Process: com.android.gallery3d, PID: 5735
java.lang.SecurityException: Permission Denial: writing android.support.v4.content.FileProvider uri content://my.package.name/external_files/Android/data/my.package.name/cache/0.5062300225583558.png from pid=5735, uid=10071 requires the provider be exported, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1683)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:621)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1000)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:742)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:718)
at com.android.gallery3d.filtershow.crop.CropActivity$BitmapIOTask.<init>(CropActivity.java:408)
at com.android.gallery3d.filtershow.crop.CropActivity.startBitmapIO(CropActivity.java:339)
at com.android.gallery3d.filtershow.crop.CropActivity.startFinishOutput(CropActivity.java:311)
at com.android.gallery3d.filtershow.crop.CropActivity$1.onClick(CropActivity.java:117)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22260)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
09-30 13:19:44.376 11909-11942/volo.global.pingbing E/FA: Task exception on worker thread: java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'com.google.firebase.iid.zzg' appears in /data/app/volo.global.pingbing-1/base.apk): com.google.android.gms.measurement.internal.zzt.zzEd(Unknown Source)

推荐答案

List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            grantUriPermission(packageName, photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }

这篇关于权限拒绝:编写android.support.v4.content.FileProvider uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆