0

I am trying to handle use cases where the user doesn't have Play set up correctly. It seems extremely straight forward, but I can't get the dialog to do anything. I have the following code in onCreate for a FragmentActivity that uses Maps v2. I have ensured that execution does go inside the if statements.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    this.helper = (DatabaseHelper) OpenHelperManager.getHelper(this, DatabaseHelper.class);

    int googlePlayStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if(googlePlayStatus != ConnectionResult.SUCCESS) {
        if(GooglePlayServicesUtil.isUserRecoverableError(googlePlayStatus)) {
            GooglePlayServicesUtil.getErrorDialog(googlePlayStatus, this, googlePlayStatus).show();
        }
    } 

    //... do some stuff, such as use CameraUpdateFactory which throws NPE.

}

I have tried inserting the code into another activity, without the if checks, and the dialog shows just fine.

4

1 に答える 1

1

ai が正しく取得している場合は、ダイアログ エラーを表示しようとしています。これを試して:

編集:

わかりました、私はしばらく前にあなたと同じ問題を抱えていたので、これは私のプロジェクトの1つで使用する正確なコードです. これを渡す代わりに、「isGooglePlayServicesAvailable」で「getActivity」を呼び出します。

int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, getActivity(), DIALOG_GET_GOOGLE_PLAY_SERVICES);
    dialog.show();
}
于 2013-11-07T17:38:05.200 に答える