From 7d0067e29838d87da659f00360fb09a092e4da98 Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Thu, 12 Apr 2018 04:07:50 -0700 Subject: [PATCH] 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 --- .../android/exoplayer2/demo/PlayerActivity.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java index 562ba7919a..a876364a84 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java @@ -215,11 +215,16 @@ public class PlayerActivity extends Activity @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - initializePlayer(); + if (grantResults.length > 0) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + initializePlayer(); + } else { + showToast(R.string.storage_permission_denied); + finish(); + } } else { - showToast(R.string.storage_permission_denied); - finish(); + // Empty results are triggered if a permission is requested while another request was already + // pending and can be safely ignored in this case. } }