Android BLE 如何劫持应用 OS 配对过程

Android BLE how can app hijack OS pairing process

我正在使用 BLE 设备,它需要在配对期间设置设备时间。在任何其他时间写入时间特性都不会有效设置时间。

目前我正在使用AndroidOS的蓝牙管理器进行配对。并且配对的进度通过广播意图通知我的应用程序。

public void onReceive(Context context, Intent intent) {
    ....
    switch (action) {
    case BluetoothDevice.ACTION_BOND_STATE_CHANGED: 
        if(state == BluetoothDevice.BOND_BONDED){
            //Write to the Date-Time Characteristic
        }
        else if(state==BluetoothDevice.BOND_BONDING){
        }
        else if(state==BluetoothDevice.BONE_NONE){
        }
     ....
     }
     ...
    }

我的问题是如何在上面注释的位置注入代码来完成日期时间的设置?显然,Android OS 蓝牙管理器在整个配对过程中并未设置时间。 Android 是否允许两个应用程序(OS 蓝牙管理器和我的应用程序)在单个连接会话中写入远程 gatt?

您可能无法写入数据时间,即配对过程中的特征(如果您不需要配对应该没问题)。原因是你可能先得到服务得到特征句柄然后再写,这可能不会发生在配对的同时;这取决于您的远程设备的安全级别设置。

My question is how to inject code to the position commented above to complete the Date-Time setting?

您可以注册一个广播接收器来接收绑定事件。

Does Android allow two applications (OS Bluetooth Manager and my application) write to the remote gatt within a single connection session?

当然可以,因为您使用的是相同的蓝牙适配器:-)