Last active
August 29, 2015 14:05
-
-
Save doyonghoon/ace4bb66c29b77f871b6 to your computer and use it in GitHub Desktop.
show an alert for updating GooglePlayService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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