How to check and update google play services |
How to update google play services
Sometimes, very essential part of your app depends on google play services for e.g. google map, google place picker etc. and in this condition what if that part stops working or user is reporting issue, that place picker is not functioning anymore ?
What will you do then?
Most of the developer run the app on their device or emulator and check is it working fine or not ? And guess what ? they are not getting any issues at all. They probably respond to user that it is working fine here. Am i right ? if yes then NO.There can be one more reason for the issue of place picker. And that can be old or outdated google play services.
To resolve this you need to check that update of google play services available or not and to do that use below code.
//CHECKS THAT GOOGLE PLAY SERVICES NEEDS UPDATE OR NOT int googlePlayApiStatus = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext());
Update Available or Not ?
You almost done !! If you want to prompt the user with an alertDialog when play services need to be updated, use below code to show dialog with update button.//IF UPDATE REQUIRES if(googlePlayApiStatus ==ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED) { showAlert(null, "Please update google play services to proceed.", "Update", "Cancel", false, new IAlertListener() { @Override public void onPositiveClick(DialogInterface dialog, int which) { //PACKAGE NAME OF GOOGLE PLAY SERVICES final String appPackageName = "com.google.android.gms"; try { //IT WILL OPEN IN GOOGLE PLAY STORE startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { //IF GOOGLE PLAY STORE APP NOT FOUND IN DEVICE IT WILL OPEN IN WEB BROWSER startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); } dialog.dismiss(); } @Override public void onNegativeClick(DialogInterface dialog, int which) { dialog.dismiss(); //YOU CAN ALSO WRITE CODE TO FINISH ACTIVITY. } }); } else { //your work here }That's all Folks, if you still have any confusion, clear them by commenting below.
And Be Updated with our YouTube Channel.
How should I modify the dialog style?It's black now.
ReplyDeleteHello qing wu,
DeleteI just used a method which generates alert dialog.
You can make your own dialog according to you.
I will write a blog on it for you shortly. Till then you can make sure that you didn't use any "holo dark theme"
Thank you. It would be great if you could help me.
Delete