LocationServices.SettingsApi重置SETTINGS_CHANGE_UNAVAILABLE标志 [英] LocationServices.SettingsApi Reset SETTINGS_CHANGE_UNAVAILABLE flag

查看:115
本文介绍了LocationServices.SettingsApi重置SETTINGS_CHANGE_UNAVAILABLE标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新至Google Play Services v7.0 +,并位于这是Android中LocationUpdates的示例,我有以下代码连接到 LocationServices.SettingsApi ,并检查用户是否拥有一切正常的应用程序接收位置更新。



$ p $ builder.addLocationRequest(mLocationRequest);
mLocationSettingsRequest = builder.build();

PendingResult< LocationSettingsResult>结果=
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);
result.setResultCallback(this);

其中这个是以下回调:

  @Override 
public void onResult(LocationSettingsResult locationSettingsResult){

final Status status = locationSettingsResult .getStatus();
Intent resolutionIntent;
switch(status.getStatusCode()){
case LocationSettingsStatusCodes.SUCCESS:
//一切正常,开始请求位置更新
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
//似乎用户需要更改设置以启用位置更新,请调用startResolutionForResult(Activity,REQUEST_CODE)
break;
案例LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
//错误,无法检索位置更新。
休息;


SUCCESS $ b $ p> RESOLUTION_REQUIRED 也可以重现,只有禁用GPS。
$ b $ SETTINGS_CHANGE_UNAVAILABLE 是交易:如果用户在步骤<$ c时选择NEVER $ c> RESOLUTION_REQUIRED 会被执行,结果会始终以此状态出现。



Google Play服务是否可以选择重设以编程方式标志当用户选择从不选项?



我知道从不似乎是 真的,不要再问我了! ,但我想创建一个选项,以防用户改变主意,当然,如果这是可能的话。



在这种情况下,我将能够再次收到状态 RESOLUTION_REQUIRED ,并要求用户在下次执行该应用程序时接受LocationUpdates。 解决方案

LocationSettingsRequest。 Builder 有一个方法 setAlwaysShow ,它改变了对话框的按钮:


总是显示对话框,没有Never选项未来
对话从这个应用程序。当此标志设置为true时,如果位置设置不满足请求,则对话框将显示
,即使
用户之前选择了从不。注意:如果您的
对话框是由
需要位置进行的明确的用户启动操作的结果,请仅使用此方法。取消此对话框还应取消
启动的操作。


取而代之的是默认的,<如果您调用 setAlwaysShow(true); ,您将只拥有 按钮>和 No ,所以用户不会选择 Never ,并且永远不会收到 SETTINGS_CHANGE_UNAVAILABLE

  LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder(); 
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
mLocationSettingsRequest = builder.build();

PendingResult< LocationSettingsResult>结果=
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);

result.setResultCallback(this);


Updating to Google Play Services v7.0+, and based in this sample for LocationUpdates in Android, I have the following code to connect to the LocationServices.SettingsApi and check if user has everything OK for the Application receive the location updates.

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    mLocationSettingsRequest = builder.build();

    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(
                    mLocationClient,
                    mLocationSettingsRequest
            );
    result.setResultCallback(this);

Where this is the following callback:

    @Override
    public void onResult(LocationSettingsResult locationSettingsResult) {

        final Status status = locationSettingsResult.getStatus();
        Intent resolutionIntent;
        switch (status.getStatusCode()) {
            case LocationSettingsStatusCodes.SUCCESS:
                // Everything is OK, starting request location updates
                break;
            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                // Seems the user need to change setting to enable locations updates, call startResolutionForResult(Activity, REQUEST_CODE)
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                // Error, cannot retrieve location updates.
                break;
        }
    }

The SUCCESS it OK to reproduce, just keep GPS enabled.

The RESOLUTION_REQUIRED is also OK to reproduce, only disable GPS.

The SETTINGS_CHANGE_UNAVAILABLE is the deal: If user select "NEVER" when the step RESOLUTION_REQUIRED is executed, the result will come with this status always.

Did the Google Play Services has a option to reset programmatically the flag when user select the "NEVER" option?

I know that "NEVER" seems to be "Really, don't ask me again!!!", but I thinking to create a option in case the user change his mind, of course, if this can be possible.

In this case I'll be able to receive the status RESOLUTION_REQUIRED again and ask to user to accept the LocationUpdates when the app is executed next time.

解决方案

LocationSettingsRequest.Builder has a method setAlwaysShow that changes the buttons of the dialog:

Always show the dialog, without the "Never" option to suppress future dialogs from this app. When this flag is set to true, the dialog will show up if the location settings do not satisfy the request, even if a user has previously chosen "Never". NOTE: Only use this method if your dialog is the result of an explicit user-initiated action that requires location to proceed. Canceling this dialog should also cancel the initiated action.

Instead the default Yes, Not now and Never buttons if you call setAlwaysShow(true); you will have only Yes and No, so the user won't choose Never and you will never receive SETTINGS_CHANGE_UNAVAILABLE

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true); 
mLocationSettingsRequest = builder.build();

PendingResult<LocationSettingsResult> result =
        LocationServices.SettingsApi.checkLocationSettings(
                mLocationClient,
                mLocationSettingsRequest
        );

result.setResultCallback(this);

这篇关于LocationServices.SettingsApi重置SETTINGS_CHANGE_UNAVAILABLE标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆