2016-01-06 120 views
0

我想提示用户更改位置精度,如谷歌地图。
我发现的选项是使用Intent将用户导航到设置以手动更改它。
但谷歌地图做它不同,它会提示你,如果你想切换到高精度,如果你点击是它更改此设置,而无需切换到设置应用程序。Android更改位置精度

我想知道你们中的任何人是否知道任何解决方案。
谢谢

回答

0

这是代码。

if (googleApiClient == null) { 
      googleApiClient = new GoogleApiClient.Builder(getActivity()) 
        .addApi(LocationServices.API) 
        .addConnectionCallbacks(this) 
        .addOnConnectionFailedListener(this).build(); 
       googleApiClient.connect(); 

       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); //this is the key ingredient 
       //************************** 

       PendingResult<LocationSettingsResult> result = 
         LocationServices.SettingsApi.checkLocationSettings(googleApiClient, 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(
              getActivity(), 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; 
         } 
        } 
       });    }