我正在请求 Activity 中的 ACCESS_FINE_LOCATION 权限,除非用户批准此权限,否则这毫无意义,因此如果用户拒绝,我将关闭该 Activity。问题是,一旦用户拒绝了选择了“不再询问”选项的请求,我不知道如何重置该状态并在以后用户改变主意时再次询问。
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;
}
}
}
最佳答案
这完全由用户控制,因此如果您是这个意思,您不能在代码中重置它。
用户可以
clear data (Settings > Apps > your app > Storage > Clear Data)
或
uninstalling/re-install the app
关于android - 如何在没有 "Never ask again"选项的情况下请求权限对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986990/