How to persist permission in android API 19 (KitKat)?

前端 未结 2 938
情深已故
情深已故 2020-11-29 03:27

In my application I store the path of image in my SQlite db for further use. The path that I get is

content://com.android.providers.media.documents/document         


        
2条回答
  •  粉色の甜心
    2020-11-29 03:38

    The code listed below,

    // kitkat fixed (broke) content access; to keep the URIs valid over restarts need to persist access permission
    if(Utils.isKitkat())
    {
        final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
        ContentResolver resolver = getActivity().getContentResolver();
        for (Uri uri : images)
        {
            resolver.takePersistableUriPermission(uri, takeFlags);
        }
    }
    

    worked fine for me, anyway I noticed that the max number of persistable uri granted to my app is limited to 128. If I select more than 128 uri, I get the error:

    java.lang.SecurityException: Permission Denial: opening provider........
    

    just when I try to process an image for which I wasn't able to persist the permission. Can you figure out any solution?

提交回复
热议问题