37

自動エラー レポートを生成するためにACRA ( arca.ch ) を使用しています。

Google Maps Android API v2 を使用してアプリの新しいバージョンをリリースしました。GooglePlayServicesUtil.getErrorDialog によって返されたダイアログを表示しようとすると、EEPad および 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.

ご協力いただきありがとうございます。

アップデート

この問題はまだ Google によって解決されておらず、何かを聞いたらこの質問を更新します (Google バグ レポートのリンクについては CommonsWare の回答を参照してください)。それまでの間、この問題に遭遇し、アプリをクラッシュさせたくない場合は、当面の間、次のことを行っています。

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

結果コードが、または_ 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 に答える
8

Rahim のコードに基づいて、ユーザーが [戻る] ボタンを押して [Google Play Services] ダイアログを閉じ、Google Play Services がインストールされていない状態でアプリを使い続けることができないようにする機能を追加します。

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

の最初の 2 つのパラメーターの順序が実装getErrorDialog()で入れ替わっていることに注意してください。GoogleApiAvailability

于 2016-10-11T08:22:44.213 に答える