本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE屬性的具體用法?Java BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE怎麽用?Java BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createAwesomenessService
private BluetoothGattService createAwesomenessService() {
BluetoothGattService service = new BluetoothGattService(SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
// Counter characteristic (read-only, supports notifications)
BluetoothGattCharacteristic counter = new BluetoothGattCharacteristic(CHARACTERISTIC_COUNTER_UUID,
BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PERMISSION_READ);
BluetoothGattDescriptor counterConfig = new BluetoothGattDescriptor(DESCRIPTOR_CONFIG, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE);
counter.addDescriptor(counterConfig);
BluetoothGattDescriptor counterDescription = new BluetoothGattDescriptor(DESCRIPTOR_USER_DESC, BluetoothGattDescriptor.PERMISSION_READ);
counter.addDescriptor(counterDescription);
// Interactor characteristic
BluetoothGattCharacteristic interactor = new BluetoothGattCharacteristic(CHARACTERISTIC_INTERACTOR_UUID,
BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, BluetoothGattCharacteristic.PERMISSION_WRITE);
BluetoothGattDescriptor interactorDescription = new BluetoothGattDescriptor(DESCRIPTOR_USER_DESC, BluetoothGattDescriptor.PERMISSION_READ);
interactor.addDescriptor(interactorDescription);
service.addCharacteristic(counter);
service.addCharacteristic(interactor);
return service;
}
示例2: isRequiredServiceSupported
@Override
public boolean isRequiredServiceSupported(final BluetoothGatt gatt) {
final BluetoothGattService service = gatt.getService(UART_SERVICE_UUID);
if (service != null) {
mRXCharacteristic = service.getCharacteristic(UART_RX_CHARACTERISTIC_UUID);
mTXCharacteristic = service.getCharacteristic(UART_TX_CHARACTERISTIC_UUID);
}
boolean writeRequest = false;
boolean writeCommand = false;
if (mRXCharacteristic != null) {
final int rxProperties = mRXCharacteristic.getProperties();
writeRequest = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0;
writeCommand = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0;
// Set the WRITE REQUEST type when the characteristic supports it. This will allow to send long write (also if the characteristic support it).
// In case there is no WRITE REQUEST property, this manager will divide texts longer then 20 bytes into up to 20 bytes chunks.
if (writeRequest)
mRXCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
}
return mRXCharacteristic != null && mTXCharacteristic != null && (writeRequest || writeCommand);
}
示例3: onCharacteristicWriteRequest
@Override
public void onCharacteristicWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattCharacteristic characteristic, final boolean preparedWrite, final boolean responseNeeded, final int offset, final byte[] value) {
super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value);
Log.d(TAG, "onCharacteristicWriteRequest characteristic: " + characteristic.getUuid() + ", value: " + Arrays.toString(value));
if (gattServer == null) {
return;
}
if (responseNeeded) {
if (BleUuidUtils.matches(CHARACTERISTIC_REPORT, characteristic.getUuid())) {
if (characteristic.getProperties() == (BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) {
// Output Report
onOutputReport(value);
// send empty
gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, EMPTY_BYTES);
} else {
// send empty
gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, EMPTY_BYTES);
}
}
}
}
示例4: findWritableCharacteristic
private BluetoothGattCharacteristic findWritableCharacteristic(BluetoothGattService service, UUID characteristicUUID, int writeType) {
try {
BluetoothGattCharacteristic characteristic = null;
// get write property
int writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE;
if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) {
writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE;
}
List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
for (BluetoothGattCharacteristic c : characteristics) {
if ((c.getProperties() & writeProperty) != 0 && characteristicUUID.equals(c.getUuid())) {
characteristic = c;
break;
}
}
// As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties
if (characteristic == null) {
characteristic = service.getCharacteristic(characteristicUUID);
}
return characteristic;
}catch (Exception e) {
Log.e(LOG_TAG, "Error on findWritableCharacteristic", e);
return null;
}
}
示例5: isCharacteristicWrite
public static boolean isCharacteristicWrite(int property){
if ((property & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0
|| (property & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) {
return true;
}
return false;
}
示例6: writeCharacteristic
@Override
public final boolean writeCharacteristic(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);
}
示例7: writeCharacteristic
/**
* Writes the characteristic value to the given characteristic.
*
* @param characteristic the characteristic to write to
* @return true if request has been sent
*/
protected final boolean writeCharacteristic(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;
Logger.v(mLogSession, "Writing characteristic " + characteristic.getUuid() + " (" + getWriteType(characteristic.getWriteType()) + ")");
Logger.d(mLogSession, "gatt.writeCharacteristic(" + characteristic.getUuid() + ")");
return gatt.writeCharacteristic(characteristic);
}
示例8: addImmediateAlertService
private void addImmediateAlertService() {
/*
* This method must be called in UI thread. It works fine on Nexus devices but if called from other thread (f.e. from onServiceAdded in gatt server callback) it hangs the app.
*/
final BluetoothGattCharacteristic alertLevel = new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
BluetoothGattCharacteristic.PERMISSION_WRITE);
alertLevel.setValue(HIGH_ALERT);
final BluetoothGattService immediateAlertService = new BluetoothGattService(IMMEDIATE_ALERT_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
immediateAlertService.addCharacteristic(alertLevel);
mBluetoothGattServer.addService(immediateAlertService);
}
示例9: isCharacteristicWriteable
public static boolean isCharacteristicWriteable(BluetoothGattCharacteristic c) {
return (c.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) != 0;
}
示例10: decodeProperties
public static WritableMap decodeProperties(BluetoothGattCharacteristic characteristic) {
// NOTE: props strings need to be consistent across iOS and Android
WritableMap props = Arguments.createMap();
int properties = characteristic.getProperties();
if ((properties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0x0 ) {
props.putString("Broadcast", "Broadcast");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) != 0x0 ) {
props.putString("Read", "Read");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 ) {
props.putString("WriteWithoutResponse", "WriteWithoutResponse");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0x0 ) {
props.putString("Write", "Write");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0 ) {
props.putString("Notify", "Notify");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 ) {
props.putString("Indicate", "Indicate");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 ) {
// Android calls this "write with signature", using iOS name for now
props.putString("AuthenticateSignedWrites", "AuthenticateSignedWrites");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0x0 ) {
props.putString("ExtendedProperties", "ExtendedProperties");
}
// iOS only?
//
// if ((p & CBCharacteristicPropertyNotifyEncryptionRequired) != 0x0) { // 0x100
// [props addObject:@"NotifyEncryptionRequired"];
// }
//
// if ((p & CBCharacteristicPropertyIndicateEncryptionRequired) != 0x0) { // 0x200
// [props addObject:@"IndicateEncryptionRequired"];
// }
return props;
}
示例11: initService
private void initService() {
List<BluetoothGattService> list = btGatt.getServices();
BluetoothGattService service = null;
for (BluetoothGattService s : list) {
if (s.getUuid().toString().substring(4, 8).equalsIgnoreCase(serviceId)) {
service = s;
break;
}
}
if (service == null) {
onError(ErrorCode.IO);
taskConnectTimeout.cancel();
return;
}
BluetoothGattCharacteristic characteristic = null;
List<BluetoothGattCharacteristic> chars = service.getCharacteristics();
for (BluetoothGattCharacteristic c : chars) {
int props = c.getProperties();
int desiredProps = BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_NOTIFY;
if ((props & desiredProps) == desiredProps) {
characteristic = c;
break;
}
}
if (characteristic == null) {
onError(ErrorCode.IO);
taskConnectTimeout.cancel();
return;
}
charSerial = characteristic;
BluetoothGattDescriptor clientConfig = null;
List<BluetoothGattDescriptor> descs = charSerial.getDescriptors();
for (BluetoothGattDescriptor d : descs) {
if (d.getUuid().toString().substring(4, 8).equalsIgnoreCase("2902")) {
clientConfig = d;
break;
}
}
if (clientConfig == null) {
onError(ErrorCode.IO);
taskConnectTimeout.cancel();
return;
}
btGatt.setCharacteristicNotification(charSerial, true);
clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
btGatt.writeDescriptor(clientConfig);
}
示例12: decodeCharacteristicProperties
public static JSONArray decodeCharacteristicProperties(BluetoothGattCharacteristic characteristic) {
//NSMutableArray *props = [NSMutableArray new];
JSONArray props = new JSONArray();
//CBCharacteristicProperties p = [characteristic properties];
int p = characteristic.getProperties();
// NOTE: props strings need to be consistent across iOS and Android
// if ((p & CBCharacteristicPropertyBroadcast) != 0x0) {
// [props addObject:@"Broadcast"];
// }
if ((p & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0x0 ) {
props.put("Broadcast");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_READ) != 0x0 ) {
props.put("Read");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 ) {
props.put("WriteWithoutResponse");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0x0 ) {
props.put("Write");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0 ) {
props.put("Notify");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 ) {
props.put("Indicate");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 ) {
// Android calls this "write with signature", using iOS name for now
props.put("AuthenticateSignedWrites");
}
if ((p & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0x0 ) {
props.put("ExtendedProperties");
}
// iOS only
//
// if ((p & CBCharacteristicPropertyNotifyEncryptionRequired) != 0x0) {
// [props addObject:@"NotifyEncryptionRequired"];
// }
//
// if ((p & CBCharacteristicPropertyIndicateEncryptionRequired) != 0x0) {
// [props addObject:@"IndicateEncryptionRequired"];
// }
return props;
}
示例13: decodeProperties
public static JSONArray decodeProperties(BluetoothGattCharacteristic characteristic) {
// NOTE: props strings need to be consistent across iOS and Android
JSONArray props = new JSONArray();
int properties = characteristic.getProperties();
if ((properties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0x0 ) {
props.put("Broadcast");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) != 0x0 ) {
props.put("Read");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 ) {
props.put("WriteWithoutResponse");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0x0 ) {
props.put("Write");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0 ) {
props.put("Notify");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 ) {
props.put("Indicate");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 ) {
// Android calls this "write with signature", using iOS name for now
props.put("AuthenticateSignedWrites");
}
if ((properties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0x0 ) {
props.put("ExtendedProperties");
}
// iOS only?
//
// if ((p & CBCharacteristicPropertyNotifyEncryptionRequired) != 0x0) { // 0x100
// [props addObject:@"NotifyEncryptionRequired"];
// }
//
// if ((p & CBCharacteristicPropertyIndicateEncryptionRequired) != 0x0) { // 0x200
// [props addObject:@"IndicateEncryptionRequired"];
// }
return props;
}