应用程序被杀死后,如何处理蓝牙BLE设备的配对?

时间:2018-12-18 14:37:30

标签: android bluetooth bluetooth-lowenergy

我正在处理必须连接到BLE设备并向其发送通知的应用程序。当应用程序处于Forground状态时,我已成功连接并发送通知。当我的应用程序被杀死时,设备已连接,但通知未发送至BLE设备以更新状态。我已经创建了后台服务和Job Scheduler来处理BLE和我的应用程序之间的通信。

For Connecting BLE Device I have used this method.

BluetoothDevice mDevice; BluetoothGatt mConnGatt;

mConnGatt = mDevice.connectGatt(mContext,true,新的BluetoothGattCallback(){});

收到推送通知后,使用以下方法在BLE设备上写入数据: / *      *      *      *在BLE设备上写数据      * BluetoothGattCharacteristic mWriteGattCharacteristic;      * * /

private void writeDataOnGatt(final int value) {
    Log.e("GATT_BLINKING_CLASS", "writeDataOnGatt");
    if (mWriteGattCharacteristic != null) {
        // This method is only called for LED characteristic
        mWriteGattCharacteristic.setValue(value, BluetoothGattCharacteristic.FORMAT_UINT8, 0);
        final int data = mWriteGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
        Log.e("GATT_BLINKING_CLASS", "     DATA       " + data);
        if (mBluetoothGatt != null) {
            Log.e("GATT_BLINKING_CLASS", "writeDataOnGatt INSIDE");
            mBluetoothGatt.writeCharacteristic(mWriteGattCharacteristic);
        }
    } 
}

0 个答案:

没有答案