Google Play 服务 7.0 设置对话框
Posted
技术标签:
【中文标题】Google Play 服务 7.0 设置对话框【英文标题】:Google Play Services 7.0 settings Dialog 【发布时间】:2015-07-21 18:01:45 【问题描述】:Google 在他们的blog post 中描述了一个一键式设置对话框,要求用户打开他们的位置(让用户打开位置而不将他们发送到手机的设置)。 我只是在他们的 API 文档中找不到合适的方法/方法来做到这一点。
有人已经在使用它并且可以给出解释吗?
【问题讨论】:
我一直在等待这个选项,因为他们把它放出来了......***.com/questions/28759454/… 【参考方案1】:I think you can check sample project by google
【讨论】:
【参考方案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 可以解决问题。
【讨论】:
以上是关于Google Play 服务 7.0 设置对话框的主要内容,如果未能解决你的问题,请参考以下文章
如何避免 Google Play 游戏服务登录对话框自动提示?