Issue
On getting all files access permission I want to pass extra data with intent to onActivityResult even if the user didn't grant permission but what I get there is always 0 as resultCode and null as Intent data.
The code for starting activity:
public void grantFilePermission(final String requestId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
try {
intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse(String.format("package:%s", mContext.getApplicationContext(). getPackageName())));
} catch (Exception e) {
intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
}
intent.putExtra("requestId", requestId);
mContext.startActivityForResult(intent, 2296);
} else {
ActivityCompat.requestPermissions(mContext, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
}
The ActivityCompat.requestPermissions part is not relevant here. mContext is defined as FullscreenActivity int other place.
And this is my onActivityResult method:
void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2296 && data != null) {
String requestId = data.getStringExtra("requestId");
}
}
Here I always get 0 as resultCode and data is null, My main problem is with the data being null I need the requestId here even if the permission isn't granted.
Update
as @CommonsWare answered there is no result on ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION and even if it where the intent on startActivityForResult wouldn't be the intent on onActivityResult.
I managed a workaround to pass the requestId with using a hash map which the request code is the key and requestId is the value.
Solution
ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION is not documented to return a result. Hence, you cannot use it with startActivityForResult() very well, since its result will always be 0, and it will not contain any sort of result data.
I need the requestId here even if the permission isn't granted
You put that requestId on the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION Intent. Even for an action that does return a result Intent, that will be a different Intent than the one you used in startActivityForResult(). Random extras that you put on the outbound Intent are not copied into the result Intent.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.