GoogleApiClient.isConnected() return always false

前端 未结 2 689
礼貌的吻别
礼貌的吻别 2020-12-20 08:31

I\'m trying to implement leaderboard in my game. I wrote this code:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this)
           


        
相关标签:
2条回答
  • 2020-12-20 08:49

    You need to add a couple callback listeners to the Builder (or GoogleApiClient). What's most likely happening is that the login is failing because you don't have permissions yet. You need to handle that failure so that the user can authorize your app.

    More reading: http://www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one-object/

    0 讨论(0)
  • 2020-12-20 08:52

    I found out for some reason, although .connect() is asynchronous and that it would be logical to wait for a while loop immediately afterwards, it needs to apparently for some whatever reason still need to execute some things on the main UI thread, hence why your isConnected() is always returning false because that while loop is essentially blocking .connect(). If I could take a guess why I'm going to assume calling .connect() executes a piece of code which places itself in the main UI thread queue to be executed later on and by having that while loop there, you will be forever blocking that piece of code from ever executing/connecting.

    0 讨论(0)
提交回复
热议问题