Android 安卓定位对话框,不向谷歌发送数据

Android 安卓定位对话框,不向谷歌发送数据,android,gps,location,google-play-services,Android,Gps,Location,Google Play Services,在我的android应用程序中,我想显示“使用位置”对话框,请参见下图。 我遵循谷歌开发者指南,阅读了SO问题 我可以显示对话框,我唯一的问题是对话框要求 使用谷歌的定位服务,即使没有应用程序运行,也会向谷歌发送匿名位置 我不想那样!有没有办法打开对话框而不使用它 这是我的密码: /** * Prompt user to enable GPS and Location Services * @param activity */ //https://developers.google.co

在我的android应用程序中,我想显示“使用位置”对话框,请参见下图。 我遵循谷歌开发者指南,阅读了SO问题

我可以显示对话框,我唯一的问题是对话框要求

使用谷歌的定位服务,即使没有应用程序运行,也会向谷歌发送匿名位置

我不想那样!有没有办法打开对话框而不使用它

这是我的密码:

/**
 * Prompt user to enable GPS and Location Services
 * @param activity
 */
//https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi
public static void locationChecker(final Activity activity) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity).addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);

    builder.setAlwaysShow(true);

    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(activity, REQUEST_CHECK_SETTINGS);
                } catch (IntentSender.SendIntentException e) {
                    // Ignore the error.
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                EnlufDialog.showDeviceHasNoGpsToast();
                // Location settings are not satisfied. However, we have no way to fix the
                // settings so we won't show the dialog.

                break;
            }
        }
    });
}
/**
*提示用户启用GPS和定位服务
*@param活动
*/
//https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi
公共静态无效位置检查器(最终活动){
GoogleAppClient GoogleAppClient=新的GoogleAppClient.Builder(活动).addApi(LocationServices.API).build();
googleApiClient.connect();
LocationRequest LocationRequest=LocationRequest.create();
locationRequest.setPriority(locationRequest.PRIORITY\u高精度);
LocationSettingsRequest.Builder=新建LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult=LocationServices.SettingsApi.checkLocationSettings(GoogleAppClient,builder.build());
result.setResultCallback(新的ResultCallback(){
@凌驾
公共void onResult(位置设置结果){
最终状态状态=result.getStatus();
最终位置SettingsStates状态=结果。getLocationSettingsStates();
开关(status.getStatusCode()){
案例位置设置StatusCodes.SUCCESS:
//满足所有位置设置。客户端可以初始化位置
//请求在这里。
打破
案例位置设置StatusCodes.RESOLUTION_要求:
//不满足位置设置。但可以通过显示用户来修复
//对话。
试一试{
//通过调用startResolutionForResult()显示对话框,
//并在onActivityResult()中检查结果。
status.StartResult解决方案(活动、请求检查设置);
}catch(IntentSender.sendtintentexe){
//忽略错误。
}
打破
案例位置设置StatusCodes.SETTINGS\u CHANGE\u不可用:
EnlufDialog.showDeviceHasNoGpsToast();
//位置设置不满意。但是,我们无法修复此问题
//设置,这样我们就不会显示对话框。
打破
}
}
});
}

为什么这对您很重要?这是整个设备的位置设置,而不仅仅是应用程序。用户应该能够为他们的整个设备使用他们想要的任何位置提供商,并且不会影响您的应用程序。为什么这对您很重要?这是整个设备的位置设置,而不仅仅是应用程序。用户应该能够为他们的整个设备使用他们想要的任何位置提供程序,并且不会影响您的应用程序。