GoogleApiClient抛出&QUOT

GoogleApiClient抛出&QUOT

本文介绍了GoogleApiClient抛出"尚未连接&QUOT GoogleApiClient;后onConnected函数获取调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我发现的东西是不是很清楚,我约GoogleApiClient。 GoogleApiClient 有一个称为函数 onConnected 这是跑在客户端的连接(肯定的)

So i found something that is not very clear for me about GoogleApiClient.GoogleApiClient has a function called onConnected which is ran when the client is connected (for sure)

我有打电话给我自己的函数: startLocationListening 这是最终的使用号召GoogleApiClient的onConnected 功能

I got my own function called: startLocationListening which is eventually getting called on GoogleApiClient's onConnected function.

所以,我的 startLocationListening功能想不出运行没有任何GoogleApiClient连接。

code和日志:

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

...

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

    //Exception caught here below:
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
   }

的例外是:

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)

...

我的调试日志还表示,在 onConnected功能得到了名为

My debug log also says the onConnected function got called:

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

在此我得到了异常。

我失去了一些东西呢?我得到的连接的回应我跑我的FUNC,我得到了错误无法连接什么呢?加一讨厌的事情是:我用了几个星期这个位置的服务现在,从来没有得到这个错误

Am I missing something here? I got a response for "connected" i ran my func, and i got the error "not connected" whats this? Plus one annoying thing is: I used this location service for weeks now and never got this error.

E D I T:

我添加了一个更具体的日志输出,只是吹我的脑海里,检查了这一点:

I added a more specific log output, just blown my mind, check this out:

@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();
    }

在这种情况下,日志输出:

log output in this case:

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.

是的,我刚收到 mGoogleApiClient.isConnected()==假 onConnected()怎么可能?

E D I T:

由于没有人能甚至声誉赏金回答这个问题,我决定把这个报告作为谷歌的错误。下一步做什么就真的出乎我的意料。谷歌的为我的报告官方的回答:

Since nobody could answer this even with reputation bounty, i decided to report this as a bug to Google. What next came was really surprised me.Google's official answer for my report:

这个网站是为与AOSP Android源开发问题  code和开发工具,而不是谷歌应用程序或服务,如  播放服务,GMS或谷歌的API。不幸的是有没有似乎并  是一个合适的地方,报告bug与播放服务。我可以  说的是,这个网站是不是,对不起。尝试张贴在谷歌  产品论坛代替。

全部问题报告在这里。(我希望他们不会将其删除只是因为它的愚蠢)

Full issue report here. (I hope they wont remove it just because its silly)

所以,是的,我看了看谷歌产品论坛,只是coudnt找到任何话题发表这件事情,所以此刻荫不解地卡住了。

So yeah i took a look at Google Product Forums and just coudnt find any topic to post this thing, so at the moment Iam puzzled and stuck.

是否anyobody在地球上可以帮助我?

Does anyobody in planet earth could help me with this?

E D I T:

全部$ C $在引擎收录

推荐答案

我只注意到你所创建的googleApiClient在onStartCommand()。这似乎是一个坏主意。

I just noticed that you are creating the googleApiClient in onStartCommand(). This seems like a bad idea.

让我们说,你的服务被触发两次。两个googleApiClient物体会产生,但你只需要参考之一。如果一个其参考你没有执行它的回调onConnected(),您将连接在客户端,但其参考你其实有客户端可能仍是未连接。

Let's say that your service gets triggered twice. Two googleApiClient objects will get created, but you'll only have reference to one. If the one whose reference you don't have executes its callback to onConnected(), you will be connected in that client but the client whose reference you actually do have could still be unconnected.

我怀疑这是怎么回事。请尝试移动googleApiClient创作的onCreate,看看你是否得到相同的行为。

I suspect that's what's going on. Try moving your googleApiClient creation to onCreate and see if you get the same behavior.

这篇关于GoogleApiClient抛出"尚未连接&QUOT GoogleApiClient;后onConnected函数获取调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:27