0

我正在尝试处理用户未正确设置 Play 的用例。这似乎非常简单,但我无法让对话框做任何事情。我有以下代码onCreate用于FragmentActivity使用Maps v2. 我确保执行确实在 if 语句中进行。

@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.

}

我尝试将代码插入另一个活动,而不进行 if 检查,并且对话框显示得很好。

4

1 回答 1

1

如果 ai 做对了,您正试图显示对话框错误。尝试这个:

编辑:

好的,我前段时间遇到了和你一样的问题,所以这是我在我的一个项目中使用的确切代码。我在“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 回答