Nachdem ich einige untersuchen, habe ich festgestellt, dass die beste Lösung für das Vorhandensein der Google Play Services-Bibliothek und zeigt einen benutzerdefinierten Fehler manuell zu überprüfen war Dialog- oder Fehlerlayout. Es gibt einige Hilfsmethoden in GooglePlayServicesUtil
, die das ziemlich einfach machen.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int statusCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (statusCode == ConnectionResult.SUCCESS) {
// Continue with your regular activity/fragment configuration.
} else {
// Hide the map fragment so the default error message is not
// visible.
findViewById(R.id.map).setVisibility(View.GONE);
// Show a custom error message
showErrorMessage(statusCode);
}
}
private void showErrorMessage(final int statusCode) {
// I've outlined two solutions below. Pick which one works best for
// you and remove the if-block.
boolean showDialog = false;
if (showDialog) {
// This is the easiest method and simply displays a pre-configured
// error dialog
GooglePlayServicesUtil.getErrorDialog(statusCode, this, 0).show();
} else {
// Show a completely custom layout
findViewById(R.id.error).setVisibility(View.VISIBLE);
// Wire up the button to install the missing library
Button errorButton = (Button) findViewById(R.id.error_button);
errorButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
// Perform the correct action for the given status
// code!
GooglePlayServicesUtil.getErrorPendingIntent(
statusCode, getActivity(), 0).send();
} catch (CanceledException e1) {
// Pass
}
}
});
}
}
Wie bringen Sie das auf? Das Ergebnis von 'getErrorDialog()' ist nicht annähernd so störend. Davon abgesehen habe ich nichts dokumentiert, was diesen Teil der Benutzeroberfläche betrifft. – CommonsWare
Ich habe nur das Map-Fragment in ein XML-Layout eingebettet. Es zeigt diesen Inhalt an, wenn die Wiedergabedienste fehlen. Ich wusste nichts über die Fehlerdialogoption! Das scheint eine gute Lösung zu sein. – twaddington
Ja, ich würde die 'getErrorDialog()' Route gehen. Dieser ganze Teil des Maps V2-Erlebnisses ist nervtötend, aber "getErrorDialog()" schien mir am wenigsten zu nützen. :-) – CommonsWare