program story

onConnected 함수가 호출 된 후 GoogleApiClient에서 "GoogleApiClient가 아직 연결되지 않았습니다"라는 메시지가 표시됨

inputbox 2020. 10. 22. 08:00
반응형

onConnected 함수가 호출 된 후 GoogleApiClient에서 "GoogleApiClient가 아직 연결되지 않았습니다"라는 메시지가 표시됨


그래서 GoogleApiClient에 대해 명확하지 않은 것을 발견했습니다. GoogleApiClient 에는 클라이언트가 연결될 때 실행되는 onConnected 라는 함수 가 있습니다 (확실히)

결국 GoogleApiClient의 onConnected 함수 에서 호출 되는 startLocationListening 이라는 자체 함수 있습니다.

그래서 내 startLocationListening 함수는 GoogleApiClient 연결 없이는 실행할 수 없습니다.

코드 및 로그 :

@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 함수가 호출 되었다고도 나와 있습니다 .

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를 실행했는데 "연결되지 않음"오류가 발생했습니다.이게 뭐죠? 게다가 한 가지 성가신 점은 :이 위치 서비스를 몇 주 동안 사용했지만이 오류가 발생하지 않았습니다.

편집하다 :

나는 좀 더 구체적인 로그 출력을 추가했고, 내 마음을 날려 버렸다.

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

이 경우 로그 출력 :

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() == false내부 onConnected()가 어떻게 가능한지?

편집하다:

평판 현상금으로도 대답 할 수 없었기 때문에 나는 이것을 Google에 버그로보고하기로 결정했습니다. 다음에 오는 것은 정말 놀랐습니다. 내 보고서에 대한 Google의 공식 답변 :

"이 웹 사이트는 Google 앱이나 Play 서비스, GMS 또는 Google API와 같은 서비스가 아닌 AOSP Android 소스 코드 및 개발자 도구 세트와 관련된 개발자 문제를위한 것입니다. 안타깝게도 Play 서비스의 버그를 신고 할 적절한 장소가없는 것 같습니다. . 제가 말할 수있는 것은이 웹 사이트가 아니라는 것입니다. 죄송합니다. 대신 Google 제품 포럼에 게시 해보세요. "

여기에 전체 문제 보고서. (어리석기 때문에 제거하지 않기를 바랍니다)

예, 저는 Google 제품 포럼을 살펴 보았고이 글을 게시 할 주제를 찾을 수 없었습니다. 그래서 지금 Iam은 당황하고 막혔습니다.

지구에있는 누구든지 이것을 도와 줄 수 있습니까?

편집하다:

pastebin의 전체 코드


방금 onStartCommand ()에서 googleApiClient를 만들고 있음을 알았습니다. 이것은 나쁜 생각 인 것 같습니다.

서비스가 두 번 트리거된다고 가정 해 보겠습니다. 두 개의 googleApiClient 개체가 생성되지만 하나에 대한 참조 만 갖게됩니다. 참조가없는 사람이 onConnected ()에 대한 콜백을 실행하면 해당 클라이언트에 연결되지만 실제로 참조가있는 클라이언트는 여전히 연결되지 않을 수 있습니다.

그게 무슨 일인지 의심합니다. googleApiClient 생성을 onCreate로 이동하고 동일한 동작이 발생하는지 확인하십시오.


나는 같은 오류가 있었지만 내 문제는 iheanyl의 대답과 달랐습니다.

googleApiClient를 정적으로 선언했습니다. 이로 인해 Android가 서비스를 종료하지 못했습니다.


나는이 문제가 있었고 googleApiClient를 정적 객체로 선언하여 해결했습니다.


https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html

You should instantiate a client object in your Activity's onCreate(Bundle) method and then call connect() in onStart() and disconnect() in onStop(), regardless of the state.

The implementation of the GoogleApiClient appears designed for only a single instance. It's best to instantiate it only once in onCreate, then perform connections and disconnections using the single instance.


call connect() method in onStart()method

 @Override
       protected void onStart() {
           super.onStart();

           // Call GoogleApiClient connection when starting the Activity
           googleApiClient.connect();
       }

       @Override
       protected void onStop() {
           super.onStop();

           // Disconnect GoogleApiClient when stopping Activity
           googleApiClient.disconnect();
       }

I think I found the root of the problem and it has nothing to do with the API. I have faced this issued every time I install the app. By the way just like the most popular comment I only have one googleApiClient upon pause and resume. What I noticed is that the permission request to get geolocation access pops up. As you know in your activity this is going to turn into a pause, and once the popup is gone it resumes your activity. Most likely your googleClient is also chained to those events to disconnect and connect. You can tell there is no connection once the permission is accepted and you are about to perform the googleApiClient task.

 if(googleApiClient.isConnected()){

        rxPermissions
                .request(Manifest.permission.ACCESS_FINE_LOCATION)
                .subscribe(granted -> {

                 if (granted) {
                        //here it could be client is already disconnected!!     
                        _geolocateAddress(response);
                    } else {
                        // Oups permission denied
                    }
                });
    }

You can skip disconnecting and connecting as you set a flag which is true before permission and once the googleApiClient task is completed or granted is false.

if(googleApiClient.isConnected()){
        isRequestingPermission = true;
        rxPermissions
                .request(Manifest.permission.ACCESS_FINE_LOCATION)
                .subscribe(granted -> {
                    if (granted && googleApiClient.isConnected()) {
                        //Once the task succeeds or fails set flag to false
                        //at _geolocateAddress
                        _geolocateAddress(response);
                    } else {
                        // Oups permission denied
                        isRequestingPermission = false;
                    }
                });
    }

We could also split doing permission alone, and if granted then make the task call. Ok, I am going to confess I am using a fragment, and I reinstalled the app even rotated the screen on permissions and once granted, the result showed up. I hope this helps other people.

  • You don't have to uninstall the app. Simply go to setting/application manager/your app/ permissions and turn any off, then test the app again.

I had this issue when I accidentaly but googleApiClient.connect() in oncreate and onresume. Just removed it from oncreate.


moving the googleApi creation to onCreate resolved the issue for me.

참고URL : https://stackoverflow.com/questions/29343922/googleapiclient-is-throwing-googleapiclient-is-not-connected-yet-after-onconne

반응형