googleApiClient.connect (); не подключается - PullRequest
0 голосов
/ 05 апреля 2020

Я учусь использовать Android Studio, но у меня есть проблема, которую я не вижу, чтобы решить, даже глядя на сообщения (так что я могу что-то упустить).

Я вызываю метод .connnect () моей переменной googleApiClient. Но, похоже, это не работает, поскольку я получаю это исключение:

java.lang.IllegalStateException: GoogleApiClient is not connected yet.

Я сделал «если», чтобы проверить, подключен ли googleApiClient, но он говорит, что это не так.

это метод, который у меня есть:

protected synchronized void buildGoogleApiClient()
    {
        googleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

        googleApiClient.connect();

        if (googleApiClient.isConnected())
            Log.d("GoogleApiClient", "buildGoogleApiClient: is connected");
        else
            Log.d("GoogleApiClient", "buildGoogleApiClient: is not connected");
    }

это журнал, который я получаю:

    W/System: ClassLoader referenced unknown path: 
D/ApplicationLoaders: ignored Vulkan layer search path /data/app/com.google.android.gms-2/lib/x86:/data/app/com.google.android.gms-2/base.apk!/lib/x86 for namespace 0xaf835090
W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000001a/n/x86
    ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000001a/n/armeabi-v7a
    ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000001a/n/armeabi
I/Google Maps Android API: Google Play services client version: 12451000
I/Google Maps Android API: Google Play services package version: 200914022
D/TelephonyManager: creating subscriptionInfo Record, context : android.app.Application@41c05e5
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/Google Maps Android API: Deprecation notice: In a future release, indoor will no longer be supported on satellite, hybrid or terrain type maps. Even where indoor is not supported, isIndoorEnabled() will continue to return the value that has been set via setIndoorEnabled(), as it does now. By default, setIndoorEnabled is 'true'. The API release notes (https://developers.google.com/maps/documentation/android-api/releases) will let you know when indoor support becomes unavailable on those map types.
D/GoogleApiClient: buildGoogleApiClient: is not connected
D/GoogleMapsActivity: url = https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=0.0,0.0&radius=10000&type=museum&sensor=true&key=AIzaSyCaXlPdUWMMtSJp7047ZF5tWbEPln5zqQo
W/Google Maps Android API: Deprecation notice: In a future release, indoor will no longer be supported on satellite, hybrid or terrain type maps. Even where indoor is not supported, isIndoorEnabled() will continue to return the value that has been set via setIndoorEnabled(), as it does now. By default, setIndoorEnabled is 'true'. The API release notes (https://developers.google.com/maps/documentation/android-api/releases) will let you know when indoor support becomes unavailable on those map types.
D/GoogleApiClient: buildGoogleApiClient: is not connected
D/GoogleMapsActivity: url = https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=0.0,0.0&radius=10000&type=museum&sensor=true&key=AIzaSyCaXlPdUWMMtSJp7047ZF5tWbEPln5zqQo
I/PGA: PgaSocketInit: opened /dev/bstpgaipc: fd = 82
    Attempting to create new SOCKET connection pid = 9209, tid = 9394
I/PGA: PgaSocketInitClientPgaIpc: data mapped to 0x9f97e000
    New SOCKET connection: edu.uoc.android (pid 9209, tid 9394)
W/Google Maps Android API: Deprecation notice: In a future release, indoor will no longer be supported on satellite, hybrid or terrain type maps. Even where indoor is not supported, isIndoorEnabled() will continue to return the value that has been set via setIndoorEnabled(), as it does now. By default, setIndoorEnabled is 'true'. The API release notes (https://developers.google.com/maps/documentation/android-api/releases) will let you know when indoor support becomes unavailable on those map types.
D/GoogleApiClient: buildGoogleApiClient: is not connected
D/GoogleMapsActivity: url = https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=0.0,0.0&radius=10000&type=museum&sensor=true&key=AIzaSyCaXlPdUWMMtSJp7047ZF5tWbEPln5zqQo
D/OpenGLRenderer: endAllActiveAnimators on 0x8d5c8400 (RelativeLayout) with handle 0x8d4d73d0
D/PATATA: Connection established. Fetching location ..
D/AndroidRuntime: Shutting down VM
    procName from cmdline: edu.uoc.android
E/AndroidRuntime: in writeCrashedAppName, pkgName :edu.uoc.android
D/AndroidRuntime: file written successfully with content: edu.uoc.android StringBuffer : ;edu.uoc.android
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: edu.uoc.android, PID: 9209
    java.lang.IllegalStateException: GoogleApiClient is not connected yet.
        at com.google.android.gms.common.api.internal.zaak.execute(Unknown Source)
        at com.google.android.gms.common.api.internal.zabe.execute(Unknown Source)
        at com.google.android.gms.common.api.internal.zaaw.execute(Unknown Source)
        at com.google.android.gms.internal.location.zzq.requestLocationUpdates(Unknown Source)
        at edu.uoc.android.Activity_Map.onConnected(Activity_Map.java:188)
        at com.google.android.gms.common.internal.GmsClientEventManager.onConnectionSuccess(Unknown Source)
        at com.google.android.gms.common.api.internal.zaaw.zab(Unknown Source)
        at com.google.android.gms.common.api.internal.zaak.zaaq(Unknown Source)
        at com.google.android.gms.common.api.internal.zaak.onConnected(Unknown Source)
        at com.google.android.gms.common.api.internal.zabe.onConnected(Unknown Source)
        at com.google.android.gms.common.api.internal.zaq.onConnected(Unknown Source)
        at com.google.android.gms.common.internal.zaf.onConnected(Unknown Source)
        at com.google.android.gms.common.internal.BaseGmsClient$zzf.zzm(Unknown Source)
        at com.google.android.gms.common.internal.BaseGmsClient$zza.zza(Unknown Source)
        at com.google.android.gms.common.internal.BaseGmsClient$zzc.zzo(Unknown Source)
        at com.google.android.gms.common.internal.BaseGmsClient$zzb.handleMessage(Unknown Source)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6138)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
I/Process: Sending signal. PID: 9209 SIG: 9
Process 9209 terminated.

Я вызываю buildGoogleEnabled () для метода onMapReady

@Override
public void onMapReady(GoogleMap googleMap) {
    Object transferData[] = new Object[2];
    GetNearbyPlacesData getNearbyPlacesData = new GetNearbyPlacesData();

    mMap = googleMap;
    //Ponemos el modo terreno
    mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
    {
        buildGoogleApiClient();

        mMap.setMyLocationEnabled(true);
    }

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    mMap.clear();
    String url = getUrl(latitide, longitude, "museum");
    transferData[0] = mMap;
    transferData[1] = url;

    getNearbyPlacesData.execute(transferData);
    Toast.makeText(this, "Searching for Nearby Museums...", Toast.LENGTH_SHORT).show();
    Toast.makeText(this, "Showing Nearby Museums...", Toast.LENGTH_SHORT).show();
}
...