如果用户需要更新他们的谷歌播放服务,如何处理



我刚刚将我的应用程序更新到新的谷歌播放服务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.

我做错了什么?

getErrorDialog() 返回一个Dialog 。您仍然需要显示它,例如通过 DialogFragment .它不显示自己。

最新更新