Search code examples
javaandroidandroid-permissions

Disable "don't ask again" radio button that appears if users deny permissions a second time


My app requires permissions in order to run. If users deny permissions on the initial run it will close. If they run the app a second time and deny permissions again, the third time they attempt to run the app and it requests permissions, there will also appear a radio button in the dialog with the option "Don't ask again". If the user clicks that then the app is going to close, and the next time they run it permissions will not be asked, resulting in an endless loop hole. The user will be opening the app and it will be crashing forever, unless they uninstall and reinstall the app. How do we solve this problem? can we code so that the radio button never appears no matter how many times users deny permissions? is there an other non obvious way i am missing? i can tell this will be a challenge to crack...

public void requestPermissions() {
    //Requesting permissions.
    ActivityCompat.requestPermissions(this,new String[] {
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.RECORD_AUDIO
    }, REQUEST_PERMISSION_CODE);
}

public boolean checkPermissionFromDenice() {
    //Checking whether permissions have been granted.
    int write_external_storage_result = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int record_audio_result = ContextCompat.checkSelfPermission(this,Manifest.permission.RECORD_AUDIO);
    return write_external_storage_result == PackageManager.PERMISSION_GRANTED && record_audio_result == PackageManager.PERMISSION_GRANTED;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    //Returns user's input regarding the requested permissions.
    if (requestCode == REQUEST_PERMISSION_CODE) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
            finish(); //Killing the activity in case user accepts permissions so they set in.
        } else {
            Toast.makeText(this, "Permission not granted", Toast.LENGTH_SHORT).show();
            finishAffinity(); //Terminating the application in case user denies permissions.
        }
    }
}

Solution

  • You should harden your app against users that are unwilling to grant permissions. You should warn them that the app will not work and if the permissions are not granted later, give the users instructions how they can reset their permission settings and otherwise refuse to run the rest of the app.

    Note that this is a drastic measure and you should only do so if the permission is absolutely required for functionality of your app. If there are some features that are still usable without this particular permission, then you should still allow users to do them.