Working with BLE Android 4.3 how to write characteristics?

后端 未结 4 2139
清歌不尽
清歌不尽 2020-12-14 09:16

I am working on a BLE project (Android application) using Android 4.3 API, i have used sample BLE app it is only reading characteristics in DeviceControlActivity.activity, b

4条回答
  •  一向
    一向 (楼主)
    2020-12-14 09:47

    public boolean writeCharacteristic(byte value[],int type){
        //check mBluetoothGatt is available
        if (mBluetoothGatt == null) {
            Log.e(TAG, "lost connection");
            return false;
        }
        BluetoothGattService Service = mBluetoothGatt.getService(UUID_SIMPLESERVICE);
        if (Service == null) {
            Log.e(TAG, "service not found!");
            //////////NO service found...........
             return false;
        }
        BluetoothGattCharacteristic charac1 = null;
        boolean status1 = false;
    
        if(type==1) {
            charac1 = Service.getCharacteristic(UUID_PORT1);
            charac1.setValue(value);
            status1 = mBluetoothGatt.writeCharacteristic(charac1);
            Log.v("________BLESERVICE____", "___WRITE CHARATERISTICS STATUS:_________"+status1);
            onReliableWriteCompleted(status1);
        }
        if (charac1 == null) {
            Log.e(TAG, "char not found!");
            return false;
        }
    
        Log.v("___TYPE___","______________________"+type);
        return status1;
    }
    

提交回复
热议问题