How to check Google Play services version?

前端 未结 12 1225
走了就别回头了
走了就别回头了 2020-11-28 03:44

In my application, I need to check Google Play services version (which is installed in user\'s device). Is it possible ? And if yes, how can I do that? I searched Google but

12条回答
  •  半阙折子戏
    2020-11-28 04:03

    From newer updates i have ended up with this code, i have made a handy method to manage all stuff related to it..

    All details related to availability of Service and related details are available here.

     private void checkPlayService(int PLAY_SERVICE_STATUS)
        {
            switch (PLAY_SERVICE_STATUS)
            {
                case ConnectionResult.API_UNAVAILABLE:
                    //API is not available
                    break;
                case ConnectionResult.NETWORK_ERROR:
                    //Network error while connection 
                    break;
                case ConnectionResult.RESTRICTED_PROFILE:
                    //Profile is restricted by google so can not be used for play services
                    break;
                case ConnectionResult.SERVICE_MISSING:
                    //service is missing
                    break;
                case ConnectionResult.SIGN_IN_REQUIRED:
                    //service available but user not signed in
                    break;
                case ConnectionResult.SUCCESS:
                    break;
            }
        }
    

    I use it like this,

    GoogleApiAvailability avail;
     int PLAY_SERVICE_STATUS = avail.isGooglePlayServicesAvailable(this);
     checkPlayService(PLAY_SERVICE_STATUS);
    

    And for version GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE; will give you.

    And one of the most useful answer i found during my research is here.

提交回复
热议问题