@Override protected boolean startOperation(BluetoothGatt bluetoothGatt) { bluetoothGattCharacteristic.setValue(data); return bluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic); } }
private void writeData(byte[] bytesBatch) { RxBleLog.d("Writing next batch"); bluetoothGattCharacteristic.setValue(bytesBatch); final boolean success = bluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic); if (!success) { throw new BleGattCannotStartException(bluetoothGatt, BleGattOperationType.CHARACTERISTIC_LONG_WRITE); } }
public void writeCharacteristic(BluetoothGattCharacteristic characteristic) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.writeCharacteristic(characteristic); } /**
public void writeCharacteristic(BluetoothGattCharacteristic characteristic) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.writeCharacteristic(characteristic); } /**
private boolean internalWriteCharacteristic(final BluetoothGattCharacteristic characteristic) { final BluetoothGatt gatt = mBluetoothGatt; if (gatt == null || characteristic == null) return false; // Check characteristic property final int properties = characteristic.getProperties(); if ((properties & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) == 0) return false; return gatt.writeCharacteristic(characteristic); }
public void write_data(String data) { characteristic_write.setWriteType(write_type); characteristic_write.setValue(data); boolean writeCharacteristic = bluetoothGatt.writeCharacteristic(characteristic_write); }
public void write_data(byte by[]) { characteristic_read.setWriteType(write_type); characteristic_write.setValue(by); boolean writeCharacteristic = bluetoothGatt.writeCharacteristic(characteristic_write); }
public void doUnLockScreen(){ mBluetoothLeCharacteristic.setValue(KEY_WORD_UNLOCK); mBlutoothGatt.writeCharacteristic(mBluetoothLeCharacteristic); mBlutoothGatt.executeReliableWrite(); } private void startscanDevice(){
public void setLinkLossNotificationLevel(String address, int alertType) { Log.d(TAG, "setLinkLossNotificationLevel() - the device " + address); if (bluetoothGatt.get(address) == null || linkLossService == null || linkLossService.getCharacteristics() == null || linkLossService.getCharacteristics().size() == 0) { somethingGoesWrong(); return; } final BluetoothGattCharacteristic characteristic = linkLossService.getCharacteristics().get(0); characteristic.setValue(alertType, BluetoothGattCharacteristic.FORMAT_UINT8, 0); bluetoothGatt.get(address).writeCharacteristic(characteristic); }
private void gattWritingStep() { Log.d(TAG, "Writing command to the Gatt, step: " + step); int index = step; if (index <= (writePackets.size() - 1)) { Log.d(TAG, "Writing: " + writePackets.get(index) + " index: " + index); mSendDataCharacteristic.setValue(writePackets.get(index)); mBluetoothGatt.writeCharacteristic(mSendDataCharacteristic); } else { clearGattTask(); } } }
private void gattWritingStep() { Log.d(TAG, "Writing command to the Gatt, step: " + step); int index = step; if (index <= (writePackets.size() - 1)) { Log.d(TAG, "Writing: " + writePackets.get(index) + " index: " + index); mSendDataCharacteristic.setValue(writePackets.get(index)); mBluetoothGatt.writeCharacteristic(mSendDataCharacteristic); } else { clearGattTask(); } } }
public void immediateAlert(String address, int alertType) { Log.d(TAG, "immediateAlert() - the device " + address); if (bluetoothGatt.get(address) == null || immediateAlertService == null || immediateAlertService.getCharacteristics() == null || immediateAlertService.getCharacteristics().size() == 0) { somethingGoesWrong(); return; } final BluetoothGattCharacteristic characteristic = immediateAlertService.getCharacteristics().get(0); characteristic.setValue(alertType, BluetoothGattCharacteristic.FORMAT_UINT8, 0); bluetoothGatt.get(address).writeCharacteristic(characteristic); Events.insert(getApplicationContext(), "immediate_alert", address, "" + alertType); }
private synchronized void doVersionRequestMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.d(TAG, "doVersionRequestMessage() start"); final VersionRequestTxMessage versionTx = new VersionRequestTxMessage(); characteristic.setValue(versionTx.byteSequence); gatt.writeCharacteristic(characteristic); Log.d(TAG, "doVersionRequestMessage() finished"); }
private synchronized void doBatteryInfoRequestMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.d(TAG, "doBatteryInfoMessage() start"); characteristic.setValue(new BatteryInfoTxMessage().byteSequence); gatt.writeCharacteristic(characteristic); Log.d(TAG, "doBatteryInfoMessage() finished"); }
private synchronized void doBatteryInfoRequestMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.d(TAG, "doBatteryInfoMessage() start"); characteristic.setValue(new BatteryInfoTxMessage().byteSequence); gatt.writeCharacteristic(characteristic); Log.d(TAG, "doBatteryInfoMessage() finished"); }
private synchronized void doVersionRequestMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.d(TAG, "doVersionRequestMessage() start"); final VersionRequestTxMessage versionTx = new VersionRequestTxMessage(); characteristic.setValue(versionTx.byteSequence); gatt.writeCharacteristic(characteristic); Log.d(TAG, "doVersionRequestMessage() finished"); }
byte[] data_to_write; // Your data BluetoothManager mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SREVICE); BluetoothAdapter mBluetoothAdapter = mBluetoothManager.getAdapter(); BluetoothDevice mDevice = mBluetoothAdapter.getRemoteDevice(....); BluetoothGatt mBG = mDevice.connectGatt(....); BluetoothGattService mSVC = mBG.getService(service_uuid); BluetoothGattCharacteristic mCH = mSVC.getCharacteristic(characteristic_uuid); mCH.setValue(data_to_write); mBG.writeCharacteristic(mCH);
private synchronized void doDisconnectMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.d(TAG, "doDisconnectMessage() start"); gatt.setCharacteristicNotification(controlCharacteristic, false); final DisconnectTxMessage disconnectTx = new DisconnectTxMessage(); characteristic.setValue(disconnectTx.byteSequence); gatt.writeCharacteristic(characteristic); gatt.disconnect(); Log.d(TAG, "doDisconnectMessage() finished"); }
private synchronized void sendAuthRequestTxMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.e(TAG, "Sending new AuthRequestTxMessage to " + getUUIDName(characteristic.getUuid()) + " ..."); authRequest = new AuthRequestTxMessage(getTokenSize()); Log.i(TAG, "AuthRequestTX: " + JoH.bytesToHex(authRequest.byteSequence)); characteristic.setValue(authRequest.byteSequence); if (gatt != null) { gatt.writeCharacteristic(characteristic); } else { Log.e(TAG, "Cannot send AuthRequestTx as supplied gatt is null!"); } }
private synchronized void sendAuthRequestTxMessage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { Log.e(TAG, "Sending new AuthRequestTxMessage to " + getUUIDName(characteristic.getUuid()) + " ..."); authRequest = new AuthRequestTxMessage(getTokenSize()); Log.i(TAG, "AuthRequestTX: " + JoH.bytesToHex(authRequest.byteSequence)); characteristic.setValue(authRequest.byteSequence); if (gatt != null) { gatt.writeCharacteristic(characteristic); } else { Log.e(TAG, "Cannot send AuthRequestTx as supplied gatt is null!"); } }