【问题标题】:Google Play Services 7.0 settings DialogGoogle Play 服务 7.0 设置对话框
【发布时间】:2015-07-21 18:01:45
【问题描述】:

Google 在他们的blog post 中描述了一个一键式设置对话框,要求用户打开他们的位置(让用户打开位置而不将他们发送到手机的设置)。 我只是在他们的 API 文档中找不到合适的方法/方法来做到这一点。

有人已经在使用它并且可以给出解释吗?

【问题讨论】:

标签: android google-play-services


【解决方案1】:
【解决方案2】:

更具体的,相关代码如下

class MainActivity extends Activity implements ResultCallback<LocationSettingsResult> {
    protected void checkLocationSettings() {
        PendingResult<LocationSettingsResult> result =
                LocationServices.SettingsApi.checkLocationSettings(
                        mGoogleApiClient,
                        mLocationSettingsRequest
                );
        result.setResultCallback(this);
    }

    @Override
    public void onResult(LocationSettingsResult locationSettingsResult) {
        final Status status = locationSettingsResult.getStatus();
        switch (status.getStatusCode()) {
            case LocationSettingsStatusCodes.SUCCESS:
                Log.i(TAG, "All location settings are satisfied.");
                startLocationUpdates();
                break;
            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" +
                        "upgrade location settings ");
                try {
                    // Show the dialog by calling startResolutionForResult(), and check the result
                    // in onActivityResult().
                    status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                } catch (IntentSender.SendIntentException e) {
                    Log.i(TAG, "PendingIntent unable to execute request.");
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " +
                        "not created.");
                break;
        }
    }
}
// This code is from https://github.com/googlesamples/android-play-location/blob/master/LocationSettings/app/src/main/java/com/google/android/gms/location/sample/locationsettings/MainActivity.java

在 LocationSettingsStatusCodes#RESOLUTION_REQUIRED 的结果回调中,Status.startResolutionForResult 可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 2017-04-05
    • 1970-01-01
    • 2018-03-31
    相关资源
    最近更新 更多