Getting Permission Denial Exception

后端 未结 6 2193
悲&欢浪女
悲&欢浪女 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:26

    Please check these questions too:
    Android KitKat securityException when trying to read from MediaStore
    Permission denial: opening provider

    For the same problem on KitKat, I used this. It's an option/workaround I had found from one of the Stack Overflow links, you will be able to select files from Downloads/Recent.

    public static final int KITKAT_VALUE = 1002;
    
    Intent intent;
    
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent();
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        startActivityForResult(intent, KITKAT_VALUE);
    } else {
        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(intent, KITKAT_VALUE);
    }
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == KITKAT_VALUE ) {
            if (resultCode == Activity.RESULT_OK) {
                // do something here
            }
        }
    }
    

    Reference: Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT http://developer.android.com/guide/topics/providers/document-provider.html#client

提交回复
热议问题