本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT屬性的具體用法?Java BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT怎麽用?Java BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWriteFirstChunkFailed
@Test
public void testWriteFirstChunkFailed() throws IOException {
InputSource inputSource = Mockito.mock(InputSource.class);
doThrow(IOException.class).when(inputSource).open();
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
WriteCommand writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
CommandResult result = CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE);
verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
Mockito.reset(commandObserver, operationCommandObserver, inputSource);
when(inputSource.nextChunk()).thenThrow(IOException.class);
writeCommand.execute(device, operationCommandObserver, gatt);
verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
}
示例2: testWriteSuccessEmpty
@Test
public void testWriteSuccessEmpty() throws IOException {
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
when(gatt.readCharacteristic(eq(gattCharacteristic))).thenReturn(true);
InputSource inputSource = Mockito.mock(InputSource.class);
when(inputSource.nextChunk()).thenReturn(null);
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
CommandResult result = CommandResult.createEmptySuccess(characteristicUUID);
verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
}
示例3: testWriteSuccess
@Test
public void testWriteSuccess() throws IOException {
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
InputSource inputSource = Mockito.mock(InputSource.class);
when(inputSource.nextChunk()).thenReturn(new byte[]{21, 22});
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
verify(commandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
verify(operationCommandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
reset(commandObserver, operationCommandObserver);
when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(false);
writeCommand.execute(device, operationCommandObserver, gatt);
verifyCommandFail();
}
示例4: testOnCharacteristicWriteFail
@Test
public void testOnCharacteristicWriteFail() throws IOException {
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
InputSource inputSource = Mockito.mock(InputSource.class);
when(inputSource.nextChunk()).thenReturn(new byte[]{21, 22});
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_FAILURE);
verifyCommandFail();
}
示例5: testOnCharacteristicWriteFai2
@Test
public void testOnCharacteristicWriteFai2() throws IOException {
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
InputSource inputSource = Mockito.mock(InputSource.class);
when(inputSource.nextChunk()).thenReturn(new byte[]{21, 22});
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
doThrow(IOException.class).when(inputSource).nextChunk();
writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);
verifyCommandFail();
}
示例6: testOnCharacteristicWriteFinished
@Test
public void testOnCharacteristicWriteFinished() throws IOException {
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
InputSource inputSource = Mockito.mock(InputSource.class);
when(inputSource.nextChunk()).thenReturn(new byte[]{12, 21});
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
when(inputSource.nextChunk()).thenReturn(null);
writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);
CommandResult result = CommandResult.createEmptySuccess(characteristicUUID);
verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
}
示例7: testOnCharacteristicWriteNextChunk
@Test
public void testOnCharacteristicWriteNextChunk() throws IOException {
when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
InputSource inputSource = Mockito.mock(InputSource.class);
when(inputSource.nextChunk()).thenReturn(new byte[]{12, 21});
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
writeCommand.execute(device, operationCommandObserver, gatt);
writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);
verify(commandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
verify(operationCommandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
}
示例8: getWriteType
protected String getWriteType(final int type) {
switch (type) {
case BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT:
return "WRITE REQUEST";
case BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE:
return "WRITE COMMAND";
case BluetoothGattCharacteristic.WRITE_TYPE_SIGNED:
return "WRITE SIGNED";
default:
return "UNKNOWN: " + type;
}
}
示例9: setUp
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
InputSource inputSource = new StringInputSource("lorem ipsum dolor sit amet");
writeCommand = new WriteCommand(
serviceUUID,
characteristicUUID,
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
inputSource,
commandObserver);
}
示例10: write
/**
* Writes data to a characteristic of a service.
*
* @param serviceUUID the UUID of the service
* @param characteristicsUUID the UUID of the characteristic.
* @param source the source of data for the write command
* @param observer the operation observer - callback
* @return this object
*/
public OperationBuilder write(UUID serviceUUID, UUID characteristicsUUID, InputSource source, CommandObserver observer) {
WriteCommand cmd = new WriteCommand(serviceUUID, characteristicsUUID, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT, source, observer);
commands.add(cmd);
return this;
}