0

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

这不会进入设置屏幕,但会启用位置什么是从 2.3 及以上 android 版本工作的最佳方法

谢谢

尼兹

4

3 回答 3

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

);
    }
于 2016-02-08T13:12:16.060 回答
0
googleApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

将上述代码行添加到locationChecker().

于 2016-12-08T05:21:11.467 回答
0

在 google play services 7.0 中很好地发现了这一点...fusedapiprovider/settingsapi 是要使用的 api.. http://android-developers.blogspot.in/2015/03/google-play-services-70-places-everyone.html ?m=1 https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi

快乐的编码..

于 2015-08-17T20:03:28.707 回答