本文介绍了GooglePlayServicesUtil.getErrorDialog为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我刚刚发布我的应用程序中使用谷歌地图的Andr​​oid API第2版的新版本。我越来越想证明由GooglePlayServicesUtil.getErrorDialog返回的对话框时,报告的EeePad和变压器垫的用户错误。没有人知道为什么会发生?

下面是相关code和logcat中所报告的ACRA:

在调用此行:

  INT结果code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(本);
如果(结果code!= ConnectionResult.SUCCESS)
{
        //那回来的对话框为空(可能是由于logcat的消息)
        对话对话框= GooglePlayServicesUtil.getErrorDialog(结果code,这一点,69);
        //所以,当我打电话的下一行,应用程序崩溃与一个NullPointerException异常
        dialog.show();
}
...
 

logcat的:

  4月十二号日至18日:21:04.531 W / GooglePlayServicesUtil(3977):谷歌Play商店的签名无效。
4月12号至18号:21:04.551 E / GooglePlayServicesUtil(3977):谷歌Play业务是无效的。无法恢复。
 

在此先感谢您的帮助,您可以提供。

更新

这个问题没有被谷歌还没有解决,一旦我听到什么(见的谷歌错误报告的链接CommonsWare的答案)我会更新这个问题。如果您遇到这个问题,不希望您的应用程序崩溃的平均时间,这里是我在做什么暂且:

 公共无效checkGooglePlayServicesAvailability()
{
    INT结果code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(本);
    如果(结果code!= ConnectionResult.SUCCESS)
    {
        对话对话框= GooglePlayServicesUtil.getErrorDialog(结果code,这一点,69);
        如果(对话!= NULL)
        {
            dialog.show();
        }
        其他
        {
            showOkDialogWithText(这一点,出事了,请确保您已安装Play商店和您已连接到互联网联系开发者详细信息,如果这种情况继续下去。);
        }
    }

    Log.d(GooglePlayServicesUtil检查,结果是:+结果code);
}

公共静态无效showOkDialogWithText(上下文的背景下,字符串的MessageText)
{
    建设者建设者=新AlertDialog.Builder(上下文);
    builder.setMessage(的MessageText);
    builder.setCancelable(真正的);
    builder.setPositiveButton(OK,NULL);
    AlertDialog对话框= builder.create();
    dialog.show();
}
 

解决方案

谷歌建议(也是在docs)调用 getErrorDialog()如果结果code是 SERVICE_MISSING SERVICE_VERSION_UPDATE_REQUIRED SERVICE_DISABLED ,所以它可能是最后一次可能的状态code(<$ C C> SERVICE_INVALID $)是是什么导致麻烦。

我用下面的code,到目前为止,似乎工作正常(测试在仿真器,平台2.3.3):

  INT结果code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity.getApplicationContext());
如果(结果code == ConnectionResult.SUCCESS){
    activity.selectMap();
}否则,如果(结果code == ConnectionResult.SERVICE_MISSING ||
           因此code == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
           因此code == ConnectionResult.SERVICE_DISABLED){
    对话对话框= GooglePlayServicesUtil.getErrorDialog(结果code,活动,1);
    dialog.show();
}
 

I'm using ACRA (arca.ch) to generate automatic error reports.

I just released a new version of my app using Google Maps Android API v2. I'm getting an error reported by EEEPad and Transformer Pad users when trying to show the dialog returned by GooglePlayServicesUtil.getErrorDialog. Does anyone know why this might happen?

Here is the relevant code and Logcat as reported by acra:

While calling this line:

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();
}
...

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.

Thanks in advance for any help you can provide.

Update

The issue has not been resolved by google yet and I will update this question once I hear anything (see CommonsWare's answer for the Google Bug report link). In the mean time if you come across this issue and don't want your app to crash, here's what I'm doing for the time being:

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();
}
解决方案

Google suggests (also in docs) calling getErrorDialog() if the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED or SERVICE_DISABLED. So it may be that the last possible status code (SERVICE_INVALID) is what's causing trouble.

I'm using the following code and so far it seems to work ok (testing in emulator, platform 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();
}

这篇关于GooglePlayServicesUtil.getErrorDialog为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 03:26