1

Bluetooth GATT インスタンスを切断して閉じると、logcat に次のように表示されます。

07-22 09:33:20.699    5095-5113/com.assaabloy.stg.cliqconnect.android W/BluetoothGatt﹕ Unhandled exception in callback
java.lang.NullPointerException
        at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:168)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:71)
        at android.os.Binder.execTransact(Binder.java:404)
        at dalvik.system.NativeStart.run(Native Method)

このエラーの直前に発生するネイティブ イベントは次のとおりです。

07-22 09:33:20.689    1260-1277/? D/BtGatt.GattService﹕ clientDisconnect() - address=84:EB:18:44:D2:04, connId=9
07-22 09:33:20.689    1260-1277/? D/BtGatt.btif﹕ btif_gattc_close
07-22 09:33:20.689    1260-1322/? D/BtGatt.btif﹕ btgattc_handle_event: Event 1005
07-22 09:33:20.689    1260-1568/? E/bt-btif﹕ Do not find the bg connection mask for the remote device
07-22 09:33:20.689    1260-1322/? D/BtGatt.btif﹕ btif_gattc_upstreams_evt: Event 5
07-22 09:33:20.689    1260-1322/? D/BtGatt.GattService﹕ onDisconnected() - clientIf=9, connId=9, address=84:EB:18:44:D2:04
07-22 09:33:20.689    1260-1328/? D/BtGatt.GattService﹕ unregisterClient() - clientIf=9
07-22 09:33:20.689    1260-1328/? D/BtGatt.btif﹕ btif_gattc_unregister_app

OSバージョン: Android 4.4.4

デバイス:ネクサス 4

誰かが何が起こっているのか説明してもらえますか?

4

4 に答える 4

0

Samsung SM G318H「Trend 2 Lite」でも同様の例外が発生しました。

D/BluetoothGatt( 4182): onClientConnectionState() - status=0 clientIf=6 device=D0:5F:B8:57:FE:33
W/BluetoothGatt( 4182): Unhandled exception in callback
W/BluetoothGatt( 4182): java.lang.NullPointerException
W/BluetoothGatt( 4182): at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:172)
W/BluetoothGatt( 4182): at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:71)
W/BluetoothGatt( 4182): at android.os.Binder.execTransact(Binder.java:404)
W/BluetoothGatt( 4182): at dalvik.system.NativeStart.run(Native Method)

状態変更ハンドラー内から再接続しようとすると:

public final void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

  switch (newState) {
     case BluetoothProfile.STATE_DISCONNECTED:
       device.connectGatt(...);
       break;
  }

}

再接続をタイマースレッドに移動することで解決しました:

    case BluetoothProfile.STATE_DISCONNECTED:
      timer.schedule(
        new TimerTask() {
          @Override
          public void run() {
            device.connectGatt(...);
          }
        }, 3000);
      break;
于 2016-12-15T20:22:27.977 に答える
0

この位置で、インスタンスBluetoothGattを呼び出そうとします。onConnectionStateChange(...)BluetoothGattCallback

それをオーバーライドしましたか?

private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        ...
        }
}
于 2015-07-22T19:48:10.533 に答える
-1

1 つの解決策は、BluetoothGatt オブジェクトで disconnect() を呼び出すことです。OnConnectionStateChange() コールバックで close() を呼び出します。

于 2015-11-20T00:08:15.833 に答える