Po wykonaniu niektórych dochodzenie, uznałem, że najlepszym rozwiązaniem było ręcznie sprawdzić obecność biblioteki Google Play i wyświetli błąd niestandardowy dialog lub układ błędów. Istnieją pewne metody użytkowe w GooglePlayServicesUtil
, które sprawiają, że jest to dość proste.
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
}
}
});
}
}
Jak ty przynosząc że się? Rezultat 'getErrorDialog()' nie jest prawie taki słaby. Mówiąc to, nie widziałem niczego udokumentowanego za wpływanie na tę część interfejsu. – CommonsWare
Po prostu fragment mapy osadzony w układzie XML. Wyświetla tę zawartość, jeśli brakuje usług odtwarzania. Nie wiedziałem o opcji okna dialogowego błędu! To wydaje się dobrym rozwiązaniem. – twaddington
Tak, idę na ścieżkę 'getErrorDialog()'. Cała ta część doświadczenia Map V2 jest do dupy, ale "getErrorDialog()" wydawało mi się najmniej ssać. :-) – CommonsWare