isGooglePlayServicesAvailable always returns 2

坚强是说给别人听的谎言 提交于 2020-01-04 02:46:11

问题


I'm trying to implement Google Play Services Library to my Android app. But there is an issue about isGooglePlayServicesAvailable function.

Although my play services is up to date, it returns 2 which means SERVICE_VERSION_UPDATE_REQUIRED according to documentation.

My code is below:

 @Override
protected void onResume() {
    super.onResume();
    int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(LoginSigninActivity.this);
    if( statusCode != ConnectionResult.SUCCESS)
    {
        Log.e("statuscode",statusCode+"");
        if(GooglePlayServicesUtil.isUserRecoverableError(statusCode))
        {
            Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
                    statusCode,
                    LoginSigninActivity.this,
                    REQUEST_CODE_RECOVER_PLAY_SERVICES);

            // If Google Play services can provide an error dialog
            if (errorDialog != null) {
                errorDialog.show();
            }
        }
        else
        {
            Toast.makeText(this, getString(R.string.toast_google_play_services_not_found),Toast.LENGTH_LONG).show();
        }
    }
}

Thanks in advance.

P.S. Error dialog is always shown.


回答1:


No it should not.

Device with android 4.4.4 has play service version 5.0.89 where as devices with android L preview has play service version 5.2.08. This is reason why android studio ask you to update your play service version to 5.2.08. So, for now use

compile 'com.google.android.gms:play-services:5.0.89' 

If you are using android L emulator, i think you should use 5.2.08.

And if you want to update your play service to 5.2 see this.




回答2:


I also faced same problem. I used latest play services version: 5.+ to develop may app. But my device which has Kitkat uses play services version: 4.4.52. It always said SERVICE_VERSION_UPDATE_REQUIRED because i build an app which uses upper version of play service but device has lower version.

My suggestion is use lower play services version to develop your app or use device which uses upper version of play service.



来源:https://stackoverflow.com/questions/25989727/isgoogleplayservicesavailable-always-returns-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!