【问题标题】:Is there any option that we can turn on access to my location in Location Services in android mobile settings from application?是否有任何选项可以让我们在应用程序的 android 移动设置中的位置服务中打开对我的位置的访问?
【发布时间】:2015-06-04 13:47:43
【问题描述】:

我想打开设置>>位置服务>>从应用程序访问我在移动设备中的位置。android中是否有任何权限。

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

【问题讨论】:

  • 你的问题不清楚你想做什么?您要访问位置还是要打开设置屏幕?

标签: android location settings android-permissions


【解决方案1】:

没有。

最近的 android 设备无权从普通应用程序更改系统设置。

http://developer.android.com/reference/android/provider/Settings.Secure.html

安全系统设置,包含应用程序可以读取但不允许写入的系统首选项。这些是用户必须通过系统 UI 或针对这些值的专用 API 显式修改的首选项,而不是由应用程序直接修改。

您可以通过IntentSettings.ACTION_*s 引导用户自行更改设置,而不是直接更改设置。 http://developer.android.com/reference/android/provider/Settings.html

【讨论】:

    【解决方案2】:

    我在我的应用程序中使用它。如果设备定位服务是关闭的,那么这个方法进入设置,你可以打开定位服务。

    if (!locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                buildAlertMessageNoGps();
            }
    
    private void buildAlertMessageNoGps() {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(getString(R.string.gps_warning))
                   .setCancelable(false)
                   .setPositiveButton(getString(R.string.enable), new DialogInterface.OnClickListener() {
                       @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                           startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                       }
                   })
                   .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                       @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                            dialog.cancel();
                       }
                   });
            final AlertDialog alert = builder.create();
            alert.show();
        }
    

    【讨论】:

      【解决方案3】:

      不,从应用程序(不是系统应用程序)我们不能 以编程方式开启定位服务

      我们只能向用户打开位置设置以手动打开设置

      【讨论】:

        猜你喜欢
        • 2020-12-19
        • 1970-01-01
        • 2012-06-19
        • 1970-01-01
        • 2016-02-13
        • 2017-05-07
        • 1970-01-01
        • 2017-08-23
        • 1970-01-01
        相关资源
        最近更新 更多