0

ジオフェンスを使用する Android アプリケーションが次のコードに追加されています。

public void register(ArrayList<Geofence> geofences){
        if(geofences == null || geofences.size() == 0) return;
        this.geofences = geofences;
        locationClient = new LocationClient(context, this, onConnectionFailedListener);
        locationClient.connect();
    }

    @Override
    public void onConnected(Bundle bundle) {
        locationClient.addGeofences(geofences, GeofenceBroadcastReceiver.getPendingIntent(context), this);
    }

    @Override
    public void onDisconnected() {
        this.locationClient = null;
    }

    @Override
    public void onAddGeofencesResult(int statusCode, String[] strings) {
        if(statusCode != LocationStatusCodes.SUCCESS){
            Log.e(getClass().getName(), "onAddGeofencesResult: " + statusCode);
            return;
        }

        listener.addRegistered(strings);
        locationClient.disconnect();
    }

時々、次の例外を受け取ります (Crashlytics リンク: http://crashes.to/s/b63ac8d5f19 ):

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
   at com.google.android.gms.internal.ff.bT()
   at com.google.android.gms.internal.hc.addGeofences()
   at com.google.android.gms.location.LocationClient.addGeofences()
   at nl.auxilium.autoreset.GeofenceManager$AddGeofenceManager.onConnected(GeofenceManager.java:140)
   at com.google.android.gms.internal.ff$c.onConnected()
   at com.google.android.gms.internal.fg.b()
   at com.google.android.gms.internal.fg.bV()
   at com.google.android.gms.internal.ff$h.b()
   at com.google.android.gms.internal.ff$h.a()
   at com.google.android.gms.internal.ff$b.eN()
   at com.google.android.gms.internal.ff$a.handleMessage()
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:158)
   at android.app.ActivityThread.main(ActivityThread.java:5751)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
   at dalvik.system.NativeStart.main(NativeStart.java)

例外が発生した場合、locationClient は接続されていませんが、コードは onConnected メソッドから玉座になっています。

誰かが私を正しい方向に向けることができますか?開発中のGalaxy S4でこのバグを再現できないようです.

4

2 に答える 2

0

接続要求を設定する必要があります

locationClient.requestLocationUpdates(REQUEST, this);

詳細はこちら https://stackoverflow.com/a/22387816

于 2014-08-05T13:09:30.150 に答える