安卓使用谷歌的位置服务对话框



我在应用程序中使用地理条件。如果用户第一次运行后的第一个开关位置,则他要求同意Google位置。但是,如果用户不同意,请初始化地理返回eror代码1000。

有什么方法可以再次要求从我的应用中使用Google位置?

我知道这个Questin,但是此对话框仅在第一次启动位置设置上启动。如果用户瓦解,恕我直言,没有办法显示对话框。还是有什么办法?

谢谢您的anwser

正如您的问题所评论的那样,我不确定您要问什么,但是您可以测试用户最初是否使用shouldShowRequestPermissionRationale不同意位置权限。

以下是我使用的请求权限文档,您可能会发现一些有用的代码。

    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;
    }

最新更新