2017-08-17 146 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(); 
} 

//[...]