我可以轻松地检测到我的设备需要更新Google Play服务应用,并使用getErrorDialogFragment()呈现提示用户更新它:
GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance();
mServiceAvailabilityCode = googleApi.isGooglePlayServicesAvailable(this);
if (mServiceAvailabilityCode == ConnectionResult.SUCCESS) {
...
else {
if (googleApi.isUserResolvableError(mServiceAvailabilityCode)) {
switch (mServiceAvailabilityCode) {
....
case SERVICE_VERSION_UPDATE_REQUIRED:
googleApi.showErrorDialogFragment(SplashActivity.this, mServiceAvailabilityCode, PLAY_SERVICES_RESOLUTION_REQUEST);
break;
....
}
然而,如果Google Play服务被禁用并已过时,则用户会看到一个带有“更新”按钮的对话框,一旦用户按下该按钮,应用程序立即返回到OnActivityResult中,我可以像这样捕获响应和请求代码:
@Override
protected void onActivityResult(int requestCode, int mServiceAvailabilityCode, Intent data) {
super.onActivityResult(requestCode, mServiceAvailabilityCode, data);
switch (requestCode) {
case PLAY_SERVICES_RESOLUTION_REQUEST:
finish();
// do i need to launch app manager-> app info for google play services ?
因此,用户在对话框上按“更新”按钮并未启动Android的Playstore并加载“Playstor服务”应用程序供用户更新,这正是我所期望的。按下“更新”后只会直接返回到onActivityResult。这就是我感到困惑的地方。Android难道不应该替我启动它吗?还是我必须在OnActivityResult中自己完成?