37

我正在使用 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();
}
...

日志猫:

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.

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

更新

谷歌尚未解决该问题,一旦我听到任何内容,我将更新此问题(请参阅 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();
}
4

4 回答 4

38

如果结果代码为,或. Google建议(也在docs中)调用。所以可能是最后一个可能的状态代码 ( ) 是造成问题的原因。getErrorDialog()SERVICE_MISSINGSERVICE_VERSION_UPDATE_REQUIREDSERVICE_DISABLEDSERVICE_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();
}
于 2013-01-04T22:37:05.080 回答
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();
    }
  }
于 2013-08-04T08:40:30.273 回答
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();
        }
    }
}
于 2014-03-26T04:41:02.857 回答
0

@Nevermore对答案的更新,因为GooglePlayServicesUtil不推荐使用方法以支持GoogleApiAvailability

GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.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 = googleApiAvailability.getErrorDialog(activity, resultCode, 1);
    dialog.show();
}

请注意,前两个参数的顺序在实现中getErrorDialog()已被调换GoogleApiAvailability

于 2016-10-11T08:22:44.213 回答