Check availability of Google Play Services in android

This blog is about how we can check that Google Play service are available or not in Device.


First of all, we can Create a method which will check Play services status with Status code.

private void checkService(int statusCode)
    {
        switch (statusCode)
        {
            case ConnectionResult.API_UNAVAILABLE:
                //API is not available in device
                break;
            case ConnectionResult.NETWORK_ERROR:
                //Network error 
                break;
            case ConnectionResult.RESTRICTED_PROFILE:
                //Profile is restricted by google.
                break;
            case ConnectionResult.SERVICE_MISSING:
                //Plat Service is missing
                break;
            case ConnectionResult.SIGN_IN_REQUIRED:
                //service available but user is not signed in
                break;
            case ConnectionResult.SUCCESS:
                //Result Sucess
break; } }


Now we can call this method with status code to check Service Status.

int statusCode =GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
        checkService(statusCode);

If there is an Error in Service code then you can get text regarding that Status code with below link.

            GoogleApiAvailability.getInstance().getErrorString(statusCode);

Even you can get Error Dialog or show Notification/ show DialogFragment from instance of GoogleApiAvailability with following methods and passing statusCode.

getErrorDialog()

showErrorDialogFragment()

showErrorNotification()

Happy Coding

Comments

Post a Comment

Popular posts from this blog

How to change the color of Hamburger icon in Toolbar Android

How to combine two Bitmap in Android

How to do Facebook Login with Custom Button Android