GooglePlayServicesUtil.getErrorDialog为null

Dis*_*Dev 36 android google-maps google-play-services google-maps-android-api-2

我正在使用ACRA(arca.ch)生成自动错误报告.

我刚刚使用Google Maps Android API v2发布了我的应用的新版本.当我试图显示GooglePlayServicesUtil.getErrorDialog返回的对话框时,EEEPad和Transformer Pad用户报告了一个错误.有谁知道为什么会这样?

以下是acra报告的相关代码和Logcat:

在调用此行时:

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(resultCode != ConnectionResult.SUCCESS)
{
        //The dialog that comes back is null (probably due to the logcat message)
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 69);
        //So when I call the next line, the app crashes with a NullPointerException
        dialog.show();
}
...
Run Code Online (Sandbox Code Playgroud)

logcat的:

12-18 04:21:04.531 W/GooglePlayServicesUtil( 3977): Google Play Store signature invalid.
12-18 04:21:04.551 E/GooglePlayServicesUtil( 3977): Google Play services is invalid. Cannot recover.
Run Code Online (Sandbox Code Playgroud)

提前感谢您提供的任何帮助.

更新

谷歌还没有解决这个问题,一旦听到任何消息我就会更新这个问题(参见CommonsWare对Google Bug报告链接的回答).与此同时,如果您遇到此问题并且不希望您的应用程序崩溃,那么这就是我目前正在做的事情:

public void checkGooglePlayServicesAvailability()
{
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if(resultCode != ConnectionResult.SUCCESS)
    {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 69);
        if(dialog != null)
        {
            dialog.show();                
        }
        else
        {
            showOkDialogWithText(this, "Something went wrong. Please make sure that you have the Play Store installed and that you are connected to the internet. Contact developer with details if this persists.");
        }
    }

    Log.d("GooglePlayServicesUtil Check", "Result is: " + resultCode);
}

public static void showOkDialogWithText(Context context, String messageText)
{
    Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(messageText);
    builder.setCancelable(true);
    builder.setPositiveButton("OK", null);
    AlertDialog dialog = builder.create();
    dialog.show();
}
Run Code Online (Sandbox Code Playgroud)

Nev*_*ore 37

谷歌建议(也在文档中)调用getErrorDialog()结果代码是SERVICE_MISSING,SERVICE_VERSION_UPDATE_REQUIREDSERVICE_DISABLED.因此,最后可能的状态代码(SERVICE_INVALID)可能是导致问题的原因.

我正在使用以下代码,到目前为止似乎工作正常(在模拟器,平台2.3.3中测试):

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity.getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS) {
    activity.selectMap();
} else if (resultCode == ConnectionResult.SERVICE_MISSING ||
           resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
           resultCode == ConnectionResult.SERVICE_DISABLED) {
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 1);
    dialog.show();
}
Run Code Online (Sandbox Code Playgroud)


Rah*_*him 22

isUserRecoverableError在尝试显示对话框之前,您似乎必须检查.

  int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  if (status != ConnectionResult.SUCCESS) {
    if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
      GooglePlayServicesUtil.getErrorDialog(status, this, 
      REQUEST_CODE_RECOVER_PLAY_SERVICES).show();
    } else {
      Toast.makeText(this, "This device is not supported.", 
          Toast.LENGTH_LONG).show();
      finish();
    }
  }
Run Code Online (Sandbox Code Playgroud)

  • +1 - GooglePlayServicesUtil.isUserRecoverableError(status)比枚举所有可能的状态更优雅. (3认同)

Dan*_*e B 8

根据Rahim的代码,我添加了阻止用户关闭Google Play服务对话框的功能(通过点击后退按钮)并继续使用未安装Google Play服务的应用:

private void checkGooglePlayServicesAvailable() {
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (status != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, 0);
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    MainActivity.this.finish();
                }
            });
            dialog.show();
        } else {
            Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show();
            finish();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)