Exception java.lang.SecurityException: reading ..MediaDocumentsProvider … requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

后端 未结 2 1908
无人及你
无人及你 2020-12-31 19:30

I found this issue only in some devices when trying to pick the picture for the profile image. While checking in the emulator these issue are not seen but on live version of

2条回答
  •  爱一瞬间的悲伤
    2020-12-31 19:52

    Try this:

    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
            }
        }
    }
    

提交回复
热议问题