GooglePlayServicesUtil.getErrorDialog does nothing

旧街凉风 提交于 2020-01-14 05:29:13

问题


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.


回答1:


If a i am getting it right, you are trying to get the dialog error to be shown. Try this:

Edited:

Ok, i was having the same problem as you some time ago, so this is the exact code i use on one of my projects. I call the 'getActivity' on 'isGooglePlayServicesAvailable' instead of passing this.

int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, getActivity(), DIALOG_GET_GOOGLE_PLAY_SERVICES);
    dialog.show();
}


来源:https://stackoverflow.com/questions/19841211/googleplayservicesutil-geterrordialog-does-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!