【问题标题】:Android :Enable location settings programatically with out leaving app or going to settings screenAndroid:以编程方式启用位置设置,无需离开应用程序或进入设置屏幕
【发布时间】:2015-11-08 11:22:49
【问题描述】:

也许已经回答了,但是是否有官方 apis 以编程方式启用位置设置而无需进入设置屏幕。

what 是 2.3 及以上 android 版本的最佳方法

谢谢

尼兹

【问题讨论】:

  • AFASIK 你不能以编程方式做到这一点。您所能做的就是通过启动意图将用户发送到位置android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
  • @MurtazaKhursheedHussain 已经做到了,但上面的应用程序图像没有让我感到奇怪。即使地图应用程序也这样做以及如何做到这一点?
  • 部分安卓默认应用拥有管理员权限。有了该权限,用户就可以进行恶意行为。
  • @MurtazaKhursheedHussain 我放的是第 3 方应用程序而不是系统应用程序,想知道他们是怎么做的吗?
  • 好吧,这似乎是一个漏洞。我们在谈论哪个应用程序?

标签: android android-location android-settings


【解决方案1】:

这会有所帮助

public void locationChecker(GoogleApiClient mGoogleApiClient, final Activity activity) {
            LocationRequest locationRequest = LocationRequest.create();
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            locationRequest.setInterval(30 * 1000);
            locationRequest.setFastestInterval(5 * 1000);
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                    .addLocationRequest(locationRequest);
            builder.setAlwaysShow(true);
            PendingResult<LocationSettingsResult> result =
                    LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
            result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
                @Override
                public void onResult(LocationSettingsResult result) {
                    final Status status = result.getStatus();
                    final LocationSettingsStates state = result.getLocationSettingsStates();
                    switch (status.getStatusCode()) {
                        case LocationSettingsStatusCodes.SUCCESS:
                            // All location settings are satisfied. The client can initialize location
                            // requests here.
                            break;
                        case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                            // Location settings are not satisfied. But could be fixed by showing the user
                            // a dialog.
                            try {
                                // Show the dialog by calling startResolutionForResult(),
                                // and check the result in onActivityResult().
                                status.startResolutionForResult(
                                        activity, 1000);
                            } catch (IntentSender.SendIntentException e) {
                                // Ignore the error.
                            }
                            break;
                        case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                            // Location settings are not satisfied. However, we have no way to fix the
                            // settings so we won't show the dialog.
                            break;
                    }
                }
            }

);
    }

【讨论】:

【解决方案2】:

【讨论】:

    【解决方案3】:
    googleApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    

    locationChecker()的末尾添加上面这行代码。

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 2013-10-31
      相关资源
      最近更新 更多