android - 如何在没有 "Never ask again"选项的情况下请求权限对话框?

标签 android android-6.0-marshmallow android-permissions user-permissions

我正在请求 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;
        }
    }
}

enter image description here

enter image description here 感谢您提前提供帮助。我可能在这里遗漏了一些微不足道的东西,或者只是一杯咖啡。如果是这样的话,请随意给我投反对票。

最佳答案

这完全由用户控制,因此如果您是这个意思,您不能在代码中重置它。

用户可以

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/

相关文章:

java - AsyncTask 中的弱引用

android - Branch.io 将抓取工具重定向到 Google Play

android - Cordova 未捕获类型错误 : Cannot set property 'require' of undefined

android - ART中AOT和JIT编译器的区别

android - Android Marshmallow 上的白色通知图标

java - 如果我使用移动数据而不是 wifi,Android 将无法运行

Android Permission Denial 启动Intent for Wallpaper Settings

android - Intent FLAG_GRANT_READ_URI_PERMISSION 在 Gingerbread 中使用 FileProvider

android - 如何将类别添加到我的 SyncAdapter

安卓6.0 : Foreground service is being removed when app is being killed