Fix permission loop problem (problem seems to be that application crashes (and is restarted) when requesting two permissions at once)

This commit is contained in:
Petr Bartos 2023-11-15 18:28:20 +01:00 committed by Simon
parent 0aaf76fa3b
commit 283c994bdd

View file

@ -89,7 +89,7 @@ import java.util.Vector;
private static final String APPLICATION = "JKXR";
private int permissionCount = 0;
private boolean permissionsGranted = false;
private static final int READ_EXTERNAL_STORAGE_PERMISSION_ID = 1;
private static final int WRITE_EXTERNAL_STORAGE_PERMISSION_ID = 2;
@ -160,15 +160,8 @@ import java.util.Vector;
GLES3JNIActivity.this,
new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
WRITE_EXTERNAL_STORAGE_PERMISSION_ID);
}
else
{
permissionCount++;
}
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
{
} else if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(
GLES3JNIActivity.this,
new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
@ -176,10 +169,10 @@ import java.util.Vector;
}
else
{
permissionCount++;
permissionsGranted = true;
}
if (permissionCount == 2) {
if (permissionsGranted) {
// Permissions have already been granted.
create();
}
@ -189,21 +182,13 @@ import java.util.Vector;
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
if (requestCode == READ_EXTERNAL_STORAGE_PERMISSION_ID) {
if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
permissionCount++;
}
else
{
if (results.length > 0 && results[0] != PackageManager.PERMISSION_GRANTED) {
System.exit(0);
}
}
if (requestCode == WRITE_EXTERNAL_STORAGE_PERMISSION_ID) {
if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
permissionCount++;
}
else
{
if (results.length > 0 && results[0] != PackageManager.PERMISSION_GRANTED) {
System.exit(0);
}
}