问题
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