12

Is there any way to allow location services again for an app (or at least show the dialog) if the user previously chose the option Never?

enter image description here

I dont find any way in code to show it again, since i always get LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE in the onResult(..) callback:

    @Override
    public void onResult(LocationSettingsResult locationSettingsResult) {
        final Status status = locationSettingsResult.getStatus();
        switch (status.getStatusCode()) {
            case LocationSettingsStatusCodes.SUCCESS:
                Log.i(TAG, "All location settings are satisfied.");
//                        startLocationUpdates();
                break;
            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" +
                        "upgrade location settings ");

                try {
                    // Show the dialog by calling startResolutionForResult(), and check the result
                    // in onActivityResult().
                    status.startResolutionForResult(activity, REQUEST_CHECK_SETTINGS);

                } catch (IntentSender.SendIntentException e) {
                    Log.i(TAG, "PendingIntent unable to execute request.");
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " +
                        "not created.");
                break;
        }
    }

The only solution i found is to reinstall the app or clear data.

4

4 回答 4

27

如果之前用户选择了“从不”选项,我没有找到任何启​​用位置服务的解决方法,所以我按照上面的@Lesvmac 回答再次要求用户删除并重新安装应用程序,但我认为这不是正确的解决方法围绕这个问题。

所以目前最好的方法是不允许“从不”选项出现在请求对话框中。尝试添加

builder.setAlwaysShow(true);

LocationSettingsRequest.Builder 这将导致只有“”和“”选项而不是默认的“从不”、“”和“现在不是”&你永远不会收到SETTINGS_CHANGE_UNAVAILABLE

这是完整的方法:

 private void requestSettings() {
    LocationSettingsRequest.Builder builder =
            new LocationSettingsRequest.Builder()
                    .setAlwaysShow(true)
                    .addLocationRequest(request);
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
                    builder.build());

    result.setResultCallback(this);
}


image_before_set_always_show

image_after_set_always_show

于 2015-09-08T12:59:00.120 回答
1

对,从不意味着从不!如果用户之前对您应用的位置权限请求回答“不是现在”,您可以生成一个询问权限的对话框。但是,如果他们选择不再让您再次询问,那将是永久设置,您必须告诉他们删除并重新安装。(如果他们的位置暂时关闭,但应用程序有权访问他们的位置,则可以生成一个对话框,要求更改设备的位置服务状态。)如果位置是应用程序的必要组件,您可以考虑在安装时要求访问。在即将推出的 Android M 中,可以为每个应用设置和重置单独的权限,有助于避免此类问题。

于 2015-07-20T19:47:13.253 回答
0

解决方案很容易也很容易错过(至少在 Android 5.1 上)......

从屏幕顶部边缘向下滑动以获取下拉菜单。按“应用权限管理”。按应用程序和您要更改权限的应用程序。瞧!

于 2016-12-27T07:58:29.093 回答
0

您需要手动允许该特定应用程序的权限以重置请求权限对话框。

打开应用信息(通过从应用启动器或设置 - 应用 - [应用名称] 拖动)

选择权限

使用“不再询问”启用您拒绝的权限

(可选)从这里再次禁用它;请注意,此时,您的应用将在需要时再次请求权限。

链接:https ://android.stackexchange.com/questions/125939/reset-the-request-permission-dialog-on-marshmallow

于 2016-08-23T00:32:10.087 回答