我在Activity中请求ACCESS_FINE_LOCATION的权限,除非用户批准此权限,否则没有任何意义,因此如果用户拒绝此操作,我将关闭活动。问题是,一旦用户通过"从不再询问" 选项拒绝请求,我就不知道如何重置该状态并在将来再次询问如果用户改变主意。
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;
}
}
}