如果用户需要更新其Google Play服务,该如何处理

时间:2013-10-31 20:07:24

标签: android google-play-services

我刚刚将我的应用更新到新的Google Play服务v4.0,显然我的设备还没有。

现在我在我的应用中检查是否有谷歌播放服务

int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if(result == ConnectionResult.SUCCESS){
    Intent i = new Intent(context,LocationActivity.class);
    i.putExtra("stationId", stationId);
    i.putExtra("messageId", messageId);
    context.startActivity(i);
}else{
    mError.handleGooglePlayServices(result);
}

并且它没有通过,所以它转到我的handleGooglePlayService方法,看起来像这样

public void handleGooglePlayServices(int result) {
    switch(result){
    case ConnectionResult.SERVICE_MISSING:
        GooglePlayServicesUtil.getErrorDialog(result, this, GOOGLE_PLAY_SERVICE_MISSING_CODE);
        break;
    case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
        GooglePlayServicesUtil.getErrorDialog(result, this, GOOGLE_PLAY_SERVICE_UPDATE_CODE);
        break;
    case ConnectionResult.SERVICE_DISABLED:
        GooglePlayServicesUtil.getErrorDialog(result, this, GOOGLE_PLAY_SERVICE_DISABLED_CODE);
        break;
    case ConnectionResult.SIGN_IN_REQUIRED:
        ConnectionResult conn3 = new ConnectionResult(
                ConnectionResult.SIGN_IN_REQUIRED, null);
        try {
            conn3.startResolutionForResult(this,
                    GOOGLE_PLAY_SERVICE_SIGN_IN_CODE);
        } catch (SendIntentException e) {
            e.printStackTrace();
        }
        break;
    case ConnectionResult.INVALID_ACCOUNT:
        ConnectionResult conn6 = new ConnectionResult(
                ConnectionResult.INVALID_ACCOUNT, null);
        try {
            conn6.startResolutionForResult(this,
                    GOOGLE_PLAY_SERVICE_INVALID_ACCT_CODE);
        } catch (SendIntentException e) {
            e.printStackTrace();
        }
        break;
    case ConnectionResult.RESOLUTION_REQUIRED:
        ConnectionResult conn7 = new ConnectionResult(
                ConnectionResult.RESOLUTION_REQUIRED, null);
        try {
            conn7.startResolutionForResult(this,
                    GOOGLE_PLAY_SERVICE_RESOLUTION_CODE);
        } catch (SendIntentException e) {
            e.printStackTrace();
        }
        break;
    }
}

当我单步执行代码时,它会给我2 SERVICE_VERSION_UPDATE_REQUIRED的结果,但是我没有得到一个对话框让我可以获得更新。

我关注公会如何设置谷歌播放服务,它只是为了做我正在做的事情

It is up to you choose the appropriate place in your app to do the following steps to check for a valid Google Play services APK. For example, if Google Play services is required for your app, you might want to do it when your app first launches. On the other hand, if Google Play services is an optional part of your app, you can do these checks if the user navigates to that portion of your app:

Query for the status of Google Play services on the device with the isGooglePlayServicesAvailable() method, which returns a result code. If the result code is SUCCESS, then the Google Play services APK is up-to-date, and you can proceed as normal. If the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then call getErrorDialog() to display an error message to the user, which allows the user to download the APK from the Google Play Store or enable it in the device's system settings.

我做错了什么?

1 个答案:

答案 0 :(得分:1)

getErrorDialog()返回Dialog。您仍需要显示它,例如通过DialogFragment。它没有表现出来。