When using the new Google Maps V2 API on Android, the user will see an error message if their device does not have the Google Play (Services) app installed. I'm wondering if it's possible to somehow override the style of this error message to make it less jarring and fit the app styling more appropriately.
This is what the error looks like:
Restart Your Phone One of the easiest ways to fix most Android problems is to restart your device. The idea behind it is pretty simple. If an app or a background service on your phone is causing Google Play Services to crash, restarting the phone would clear it off the RAM and put the device in a new state.
Open the Google Play Games app on your Android device. Tap your profile icon in the top navigation bar. Tap the email displayed under your username. Select a different account or add another.
After doing some investigating, I determined that the best solution was to manually check for the presence of the Google Play Services library and display a custom error dialog or error layout. There are some utility methods in GooglePlayServicesUtil
that make this fairly straightforward.
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
}
}
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With