As has been commented in your question, I'm not sure EXACTLY what you're asking, but you can test whether the user originally disagreed to location permissions using shouldShowRequestPermissionRationale
.
Below is some expanded code based on the Requestion Permissions documentation that I use and that you may find helpful.
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "checkMyPermissions ( " + permissionRequestCode + ") : Permissions FAILED");
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
new AlertDialog.Builder(this)
.setMessage("In order to show data this app requires location permissions")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
permissionRequestCode);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
permissionRequestCode);
}
return false;
} else {
Log.d(TAG, "checkMyPermissions ( " + permissionRequestCode + ") : Permissions Passed");
return true;
}