Crocodile
Crocodile

Reputation: 5845

How can I request the permission dialog without the "Never ask again" option?

I am requesting permission for ACCESS_FINE_LOCATION in an Activity which makes no sense unless the user approves this permission, so if the user denies this I am closing down the Activity. The problem is that once the user denies the request with the "Never ask again" option selected, I don't know how to reset that state and ask again in the future if the user changes her mind.

private void loadLocPredictions() {
    //ToDo clean the permission thingy up.
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                PERMISSIONS_REQUEST_FINE_LOCACTION);

        return;
    }
// Do stuff...
}


@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case PERMISSIONS_REQUEST_FINE_LOCACTION: {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                loadLocPredictions();
            } else {
                finish();
            }
            return;
        }
    }
}

enter image description here

enter image description here Thanks for any help in advance. I am probably missing something trivial here, or just a coffee. Feel free to downvote me if that's the case.

Upvotes: 3

Views: 1821

Answers (2)

Crocodile
Crocodile

Reputation: 5845

Matthew's answer is correct. Thanks.

In case it helps anyone: This is what Google Maps and Instagram do when the user permanently denies the permissions.

enter image description here enter image description here

enter image description here

Upvotes: 1

Matthew Shearer
Matthew Shearer

Reputation: 2795

That is entirely controlled by the user, so you can't reset it in code if that's what you mean.

The user can either

clear data (Settings > Apps > your app > Storage > Clear Data)

or

uninstalling/re-install  the app 

Upvotes: 1

Related Questions