Ada*_*gyi 74 android google-api-client google-play-services android-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): at hu.company.testproject.service.GpsService.onConnected(GpsService.java:259)
Run Code Online (Sandbox Code Playgroud)
...
我的调试日志还说调用了onConnected函数:
03-30 12:23:28.847: I/Locationing_GpsService(4936): Google_Api_Client:connected.
03-30 12:23:28.857: I/Locationing_GpsService(4936): initLocationRequest:initing_now
03-30 12:23:28.877: I/Locationing_GpsService(4936): initLocationRequest:interval_5000
03-30 12:23:28.897: I/Locationing_GpsService(4936): initLocationRequest:priority_100
03-30 12:23:28.917: I/Locationing_GpsService(4936): Starting_location_listening:now
Run Code Online (Sandbox Code Playgroud)
在此之后,我得到了例外.
我在这里错过了什么吗?我得到了"连接"的响应我运行了我的功能,我得到错误"没有连接"这是什么?另外一件烦人的事情是:我现在使用这个位置服务已经好几周了,从来没有出现过这个错误.
编辑:
我添加了一个更具体的日志输出,只是让我大吃一惊,看看这个:
@Override
public void onConnected(Bundle bundle) {
if(mGoogleApiClient.isConnected()){
log("Google_Api_Client: It was connected on (onConnected) function, working as it should.");
}
else{
log("Google_Api_Client: It was NOT connected on (onConnected) function, It is definetly bugged.");
}
initLocationRequest();
startLocationListening();
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下的日志输出:
03-30 16:20:00.950: I/Locationing_GpsService(16608): Google_Api_Client:connected.
03-30 16:20:00.960: I/Locationing_GpsService(16608): Google_Api_Client: It was NOT connected on (onConnected) function, It is definetly bugged.
Run Code Online (Sandbox Code Playgroud)
是的,我刚mGoogleApiClient.isConnected() == false进去,onConnected()怎么可能?
编辑:
由于没有人能够以声誉奖励回答这个问题,我决定将此报告为谷歌的一个错误.接下来的事情让我很惊讶.Google对我的报告的正式回答:
"这个网站是针对开发人员问题的AOSP Android源代码和开发人员工具集,而不是Google应用程序或服务,如Play服务,GMS或Google API.不幸的是,似乎没有合适的地方来报告Play服务的错误我只能说这个网站不是,对不起.请尝试在Google产品论坛上发帖."
完整问题报告在这里.(我希望他们不会因为愚蠢而删除它)
所以,是的,我看了一下谷歌产品论坛,只是找到任何主题发布这个东西,所以目前我感到困惑和卡住.
地球上的任何人都可以帮助我吗?
编辑:
pastebin中的完整代码
ihe*_*nyi 86
我刚刚注意到你在onStartCommand()中创建了googleApiClient.这似乎是一个坏主意.
假设您的服务被触发两次.将创建两个googleApiClient对象,但您只能引用一个.如果您没有的引用执行其回调到onConnected(),您将在该客户端连接,但您实际拥有的引用的客户端仍然可以是未连接的.
我怀疑这是怎么回事.尝试将googleApiClient创建移动到onCreate,看看是否有相同的行为.
| 归档时间: |
|
| 查看次数: |
46248 次 |
| 最近记录: |