Getting Permission Denial Exception

后端 未结 6 2189
悲&欢浪女
悲&欢浪女 2020-11-27 16:42

I have an activity in my app that allows the user to select several files from the device one by one, I am using an intent like this:

Intent intent = new Int         


        
6条回答
  •  清歌不尽
    2020-11-27 17:18

    Make sure you're using the ContentResolver from the Activity that requested the content, for instance:

    activity.getContentResolver()  
    

    Instead of MyApp.getContext().getContentResolver()

    It was apparently the case for me and it didn't need to add the android.permission.MANAGE_DOCUMENTS to the manifest.

    And that you call the intent using this:

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        intent.setAction(Intent.ACTION_GET_CONTENT);
    } else {
        intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    

    more info: https://developer.android.com/guide/topics/providers/document-provider.html#client

提交回复
热议问题