2017-08-17 147 views
0

我打電話給GoogleApiClient進入服務。服務第一次啓動時,將調用onConnected()。然後,該服務可通過stopSelf()停止並重新啓動,以便mGoogleApiClient(空)再次建立:GoogleApiClient - UNKNOWN_ERROR_CODE(8050)

mGoogleApiClient = new GoogleApiClient.Builder(this) 
.addApi(Nearby.CONNECTIONS_API) 
.addConnectionCallbacks(this) 
.addOnConnectionFailedListener(this) 
.build(); 

則:

mGoogleApiClient.connect() 

結果:

NearbyDiscoveryService:onConnectionFailed: :ConnectionResult {statusCode = UNKNOWN_ERROR_CODE(8050),resolution = null,message = null}

任何想法是什麼問題?谷歌沒有提供任何關於錯誤代碼8050(與Android相關)!

回答

0

我剛發現這個問題。在致電stopSelf()之前,我必須關閉GoogleApiClient的連接()

//[...] 

if(isDiscovering()) { 
    stopDiscovering(); 
} 

if (!isAdvertising()) { 
    getGoogleApiClient().disconnect(); 
    stopSelf(); 
} 

//[...]