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
This commit is contained in:
aquilescanta 2018-04-12 04:07:50 -07:00 committed by Oliver Woodman
parent 3c78dc22f6
commit 7d0067e298

View file

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