Android BLE GATT_ERROR(133) on connecting to device

后端 未结 1 609
眼角桃花
眼角桃花 2021-02-04 08:09

I am trying to connect to a BLE device using the MAC address.

BluetoothDevice device = bluetoothAdapter.getRemoteDevice(rememberedDeviceAddress)
bluetoothDevice.         


        
相关标签:
1条回答
  • 2021-02-04 08:50

    Certain devices require Bluetooth LE interactions to be run on the UI thread. So I would recommend trying something like this:

    // Create handler for main thread where mContext is application context
    mHandler = new Handler(mContext.getMainLooper());
    ...
    // Connect to BLE device from mHandler
    mHandler.post(new Runnable() {
    @Override
    public void run() {
        mBTGatt = mBTDevice.connectGatt(mContext, false, mGattCallback);
    }
    });
    

    Of course you could use Activity.runOnUiThread as well. Source: https://stackoverflow.com/a/23478737

    0 讨论(0)
提交回复
热议问题