相关疑难解决方法(0)

在连接函数调用后,GoogleApiClient正在抛出"GoogleApiClient尚未连接"

所以我找到了关于GoogleApiClient的一些不太清楚的东西. GoogleApiClient有一个名为onConnected的函数,它在客户端连接时运行(肯定)

我得到了自己的函数:startLocationListening,最终在GoogleApiClient的onConnected函数上调用.

所以我的startLocationListening函数无法在没有GoogleApiClient连接的情况下运行.

代码和日志:

@Override
public void onConnected(Bundle bundle) {
    log("Google_Api_Client:connected.");
    initLocationRequest();
    startLocationListening(); //Exception caught inside this function
}
Run Code Online (Sandbox Code Playgroud)

...

private void startLocationListening() {
    log("Starting_location_listening:now");

    //Exception caught here below:
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
   }
Run Code Online (Sandbox Code Playgroud)

例外是:

03-30 12:23:28.947: E/AndroidRuntime(4936):     java.lang.IllegalStateException: GoogleApiClient is not connected yet.
03-30 12:23:28.947: E/AndroidRuntime(4936):     at com.google.android.gms.internal.jx.a(Unknown Source)
03-30 12:23:28.947: E/AndroidRuntime(4936):     at com.google.android.gms.common.api.c.b(Unknown Source)
03-30 12:23:28.947: E/AndroidRuntime(4936):     at com.google.android.gms.internal.nf.requestLocationUpdates(Unknown Source)
03-30 12:23:28.947: E/AndroidRuntime(4936):     at hu.company.testproject.service.GpsService.startLocationListening(GpsService.java:169)
03-30 12:23:28.947: E/AndroidRuntime(4936): …
Run Code Online (Sandbox Code Playgroud)

android google-api-client google-play-services android-googleapiclient

74
推荐指数
1
解决办法
5万
查看次数