Commit 7d0067e2 by aquilescanta Committed by Oliver Woodman

Fix external storage read permissions bug

Fix bug which causes the PlayerActivity to finish whenever the
android.permission.READ_EXTERNAL_STORAGE permission is requested.

A better solution would involve not requesting permissions if a
previous request is still pending. This would involve keeping
extra state in the activity, so this solution is used to keep
the demo app's complexity at a minimum.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=192588821
parent 3c78dc22
...@@ -215,12 +215,17 @@ public class PlayerActivity extends Activity ...@@ -215,12 +215,17 @@ public class PlayerActivity extends Activity
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) { @NonNull int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
initializePlayer(); initializePlayer();
} else { } else {
showToast(R.string.storage_permission_denied); showToast(R.string.storage_permission_denied);
finish(); finish();
} }
} else {
// Empty results are triggered if a permission is requested while another request was already
// pending and can be safely ignored in this case.
}
} }
// Activity input // Activity input
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment