bluetoothGatt 无法连接目标 - 回调中未处理的异常
bluetoothGatt can't connect with target - Unhandled exception in callback
我尝试使用蓝牙 GATT 服务连接我的目标设备,
我在控制台中收到此消息但无法连接。
我试着用这个连接,
bluetoothGatt = mDiscoverderDevice.connectGatt(this, true, mGattCallback);
D/BluetoothGatt: connect() - device: 5D:BB:1E:F0:09:05, auto: true
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=b6173656-60d1-494d-bac2-dc1f1a12f294
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
D/ALERT **** :: connectwithGATTServiceandroid.bluetooth.BluetoothGatt@20128b49
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=5D:BB:1E:F0:09:05
W/BluetoothGatt: Unhandled exception in callback
W/BluetoothGatt: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
W/BluetoothGatt: at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6462)
W/BluetoothGatt: at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:897)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.widget.TextView.checkForRelayout(TextView.java:6880)
W/BluetoothGatt: at android.widget.TextView.setText(TextView.java:4063)
W/BluetoothGatt: at android.widget.TextView.setText(TextView.java:3921)
W/BluetoothGatt: at android.widget.TextView.setText(TextView.java:3896)
W/BluetoothGatt: at tel.android.com.rseremote.MainActivity.setStatus(MainActivity.java:293)
W/BluetoothGatt: at tel.android.com.rseremote.MainActivity.access0(MainActivity.java:37)
W/BluetoothGatt: at tel.android.com.rseremote.MainActivity.onConnectionStateChange(MainActivity.java:381)
W/BluetoothGatt: at android.bluetooth.BluetoothGatt.onClientConnectionState(BluetoothGatt.java:181)
W/BluetoothGatt: at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:70)
W/BluetoothGatt: at android.os.Binder.execTransact(Binder.java:446)
我认为与BLE无关。
您正在尝试从外部线程更新视图元素,如 Toast 或 TextView。
这就是为什么它说
Only the original thread that created a view hierarchy can touch its views
尝试使用 runOnUIThread 方法更新 UI 视图。
我尝试使用蓝牙 GATT 服务连接我的目标设备, 我在控制台中收到此消息但无法连接。
我试着用这个连接,
bluetoothGatt = mDiscoverderDevice.connectGatt(this, true, mGattCallback);
D/BluetoothGatt: connect() - device: 5D:BB:1E:F0:09:05, auto: true
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=b6173656-60d1-494d-bac2-dc1f1a12f294
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
D/ALERT **** :: connectwithGATTServiceandroid.bluetooth.BluetoothGatt@20128b49
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=5D:BB:1E:F0:09:05
W/BluetoothGatt: Unhandled exception in callback
W/BluetoothGatt: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
W/BluetoothGatt: at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6462)
W/BluetoothGatt: at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:897)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
W/BluetoothGatt: at android.view.View.requestLayout(View.java:17494)
W/BluetoothGatt: at android.widget.TextView.checkForRelayout(TextView.java:6880)
W/BluetoothGatt: at android.widget.TextView.setText(TextView.java:4063)
W/BluetoothGatt: at android.widget.TextView.setText(TextView.java:3921)
W/BluetoothGatt: at android.widget.TextView.setText(TextView.java:3896)
W/BluetoothGatt: at tel.android.com.rseremote.MainActivity.setStatus(MainActivity.java:293)
W/BluetoothGatt: at tel.android.com.rseremote.MainActivity.access0(MainActivity.java:37)
W/BluetoothGatt: at tel.android.com.rseremote.MainActivity.onConnectionStateChange(MainActivity.java:381)
W/BluetoothGatt: at android.bluetooth.BluetoothGatt.onClientConnectionState(BluetoothGatt.java:181)
W/BluetoothGatt: at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:70)
W/BluetoothGatt: at android.os.Binder.execTransact(Binder.java:446)
我认为与BLE无关。
您正在尝试从外部线程更新视图元素,如 Toast 或 TextView。
这就是为什么它说
Only the original thread that created a view hierarchy can touch its views
尝试使用 runOnUIThread 方法更新 UI 视图。