【问题标题】:GooglePlayServicesUtil.getErrorDialog does nothingGooglePlayServicesUtil.getErrorDialog 什么都不做
【发布时间】:2013-11-07 16:24:55
【问题描述】:

我正在尝试处理用户未正确设置 Play 的用例。这似乎非常简单,但我无法让对话框做任何事情。我在onCreate 中有以下代码,用于使用Maps v2 的FragmentActivity。我确保执行确实在 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 检查,对话框显示正常。

【问题讨论】:

  • without the if checks。 if 条件的计算结果是什么?
  • @njzk2 抱歉,我已经检查过执行是否在 if 语句中。 getErrorDialog 调用什么也没做。
  • 你确定你现在在ui线程上吗?
  • @njzk2 我想是的,我在 onCreate 方法中。
  • 你能多贴一点上下文代码吗?

标签: android google-play-services android-maps-v2


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

【讨论】:

  • 这会导致编译器错误,因为 .show() 返回 void,而您正试图将其分配给 Dialog。
猜你喜欢
  • 2019-03-08
  • 2016-12-24
  • 2017-04-18
  • 2011-08-03
  • 2014-05-11
  • 2014-09-10
  • 1970-01-01
  • 2023-03-29
  • 2013-09-28
相关资源
最近更新 更多