How to check Google Play services version?

前端 未结 12 1196
走了就别回头了
走了就别回头了 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:15

    I’ve run into the same problem this morning. And got it done by the advice from stan0. Thanks stan0.

    Only one change is needed based on the sample code from https://developers.google.com/maps/documentation/android/map.

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the
        // map.
        if (mMap == null) {
            FragmentManager mgr = getFragmentManager();
            MapFragment mapFragment = (MapFragment)mgr.findFragmentById(R.id.map);
            mMap = mapFragment.getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                // The Map is verified. It is now safe to manipulate the map.
                setUpMap();
            }else{
                // check if google play service in the device is not available or out-dated.
                GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    
                // nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
            }
        }
    }
    

    Besides, you need to add an attribute to your manifest.xml as:

    
    

    And the value of "3225130" is taken from the google-play-services_lib that your project is using. Also, that value is residing in the same location of manifest.xml in google-play-services_lib.

    Hope it will be of help.

提交回复
热议问题