Skip to content

Instantly share code, notes, and snippets.

@doyonghoon
Last active August 29, 2015 14:05
Show Gist options
  • Save doyonghoon/ace4bb66c29b77f871b6 to your computer and use it in GitHub Desktop.
Save doyonghoon/ace4bb66c29b77f871b6 to your computer and use it in GitHub Desktop.
show an alert for updating GooglePlayService
/**
* Google Play 서비스 사용 불가능 에러 다이얼로그
* */
private Dialog mGooglePlayServiceErrorDialog = null;
/**
* Google Play 서비스 버전 낮아서 업데이트하러 마켓으로 보내는 다이얼로그
* */
private AlertDialog mGooglePlayServiceUpdateDialog = null;
private boolean checkGooglePlayServiceVersion() {
final int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
switch (resultCode) {
case ConnectionResult.SUCCESS:
return true;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
if (mGooglePlayServiceUpdateDialog == null) {
AlertDialog.Builder updateDialog = new AlertDialog.Builder(getActivity())
.setTitle("<title goes here>")
.setMessage("<message goes here>");
updateDialog.setPositiveButton("<positive button title goes here>", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (getActivity() != null)
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.gms")));
}
});
mGooglePlayServiceUpdateDialog = updateDialog.create();
}
if (!mGooglePlayServiceUpdateDialog.isShowing()) {
mGooglePlayServiceUpdateDialog.show();
}
return false;
default:
if (mGooglePlayServiceErrorDialog == null) {
mGooglePlayServiceErrorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, getActivity(), REQUEST_GOOGLE_PLAY_SERVICES);
mGooglePlayServiceErrorDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
getBaseActivity().finish();
}
});
mGooglePlayServiceErrorDialog.show();
}
if (!mGooglePlayServiceErrorDialog.isShowing()) {
mGooglePlayServiceErrorDialog.show();
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment