當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGattCharacteristic.PROPERTY_WRITE屬性代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.PROPERTY_WRITE屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.PROPERTY_WRITE屬性的具體用法?Java BluetoothGattCharacteristic.PROPERTY_WRITE怎麽用?Java BluetoothGattCharacteristic.PROPERTY_WRITE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.bluetooth.BluetoothGattCharacteristic的用法示例。


在下文中一共展示了BluetoothGattCharacteristic.PROPERTY_WRITE屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initGatt

@Override
	protected Queue<BleManager.Request> initGatt(final BluetoothGatt gatt) {
		final BluetoothGattService service = gatt.getService(UART_SERVICE_UUID);
		mTXCharacteristic = service.getCharacteristic(UART_TX_CHARACTERISTIC_UUID);
		mRXCharacteristic = service.getCharacteristic(UART_RX_CHARACTERISTIC_UUID);

		final int rxProperties = mRXCharacteristic.getProperties();
		boolean writeRequest = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 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);

		// We don't want to enable notifications on TX characteristic as we are not showing them here. A watch may be just used to send data. At least now.
//		final LinkedList<BleManager.Request> requests = new LinkedList<>();
//		requests.push(BleManager.Request.newEnableNotificationsRequest(mTXCharacteristic));
//		return requests;
		return null;
	}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:20,代碼來源:UARTProfile.java

示例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);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:23,代碼來源:UARTManager.java

示例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);
            }
        }
    }
}
 
開發者ID:kshoji,項目名稱:BLE-HID-Peripheral-for-Android,代碼行數:24,代碼來源:HidPeripheral.java

示例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;
	}
}
 
開發者ID:lenglengiOS,項目名稱:react-native-blue-manager,代碼行數:29,代碼來源:Peripheral.java

示例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;
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:7,代碼來源:BluetoothUtils.java

示例6: send

/**
 * Sends the given text to RX characteristic.
 * @param text the text to be sent
 */
public void send(final String text) {
	// Are we connected?
	if (mRXCharacteristic == null)
		return;

	// An outgoing buffer may not be null if there is already another packet being sent. We do nothing in this case.
	if (!TextUtils.isEmpty(text) && mOutgoingBuffer == null) {
		final byte[] buffer = mOutgoingBuffer = text.getBytes();
		mBufferOffset = 0;

		// Depending on whether the characteristic has the WRITE REQUEST property or not, we will either send it as it is (hoping the long write is implemented),
		// or divide it into up to 20 bytes chunks and send them one by one.
		final boolean writeRequest = (mRXCharacteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0;

		if (!writeRequest) { // no WRITE REQUEST property
			final int length = Math.min(buffer.length, MAX_PACKET_SIZE);
			final byte[] data = new byte[length]; // We send at most 20 bytes
			System.arraycopy(buffer, 0, data, 0, length);
			mBufferOffset += length;
			mRXCharacteristic.setValue(data);
		} else { // there is WRITE REQUEST property
			mRXCharacteristic.setValue(buffer);
			mBufferOffset = buffer.length;
		}
		getApi().writeCharacteristic(mRXCharacteristic);
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:31,代碼來源:UARTProfile.java

示例7: 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);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:13,代碼來源:BleManager.java

示例8: 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);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:20,代碼來源:BleManager.java

示例9: addLinklossService

private void addLinklossService() {
	/*
	 * 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 linklossAlertLevel = new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE
			| BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_READ);
	linklossAlertLevel.setValue(HIGH_ALERT);
	final BluetoothGattService linklossService = new BluetoothGattService(LINKLOSS_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
	linklossService.addCharacteristic(linklossAlertLevel);
	mBluetoothGattServer.addService(linklossService);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:11,代碼來源:ProximityManager.java

示例10: send

/**
 * Sends the given text to RX characteristic.
 * @param text the text to be sent
 */
public void send(final String text) {
	// Are we connected?
	if (mRXCharacteristic == null)
		return;

	// An outgoing buffer may not be null if there is already another packet being sent. We do nothing in this case.
	if (!TextUtils.isEmpty(text) && mOutgoingBuffer == null) {
		final byte[] buffer = mOutgoingBuffer = text.getBytes();
		mBufferOffset = 0;

		// Depending on whether the characteristic has the WRITE REQUEST property or not, we will either send it as it is (hoping the long write is implemented),
		// or divide it into up to 20 bytes chunks and send them one by one.
		final boolean writeRequest = (mRXCharacteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0;

		if (!writeRequest) { // no WRITE REQUEST property
			final int length = Math.min(buffer.length, MAX_PACKET_SIZE);
			final byte[] data = new byte[length]; // We send at most 20 bytes
			System.arraycopy(buffer, 0, data, 0, length);
			mBufferOffset += length;
			mRXCharacteristic.setValue(data);
		} else { // there is WRITE REQUEST property
			mRXCharacteristic.setValue(buffer);
			mBufferOffset = buffer.length;
		}
		writeCharacteristic(mRXCharacteristic);
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:31,代碼來源:UARTManager.java

示例11: isCharacteristicWriteable

public static boolean isCharacteristicWriteable(BluetoothGattCharacteristic c) {
    return (c.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) != 0;
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:3,代碼來源:BluetoothUtilImpl.java

示例12: 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;
	}
 
開發者ID:lenglengiOS,項目名稱:react-native-blue-manager,代碼行數:51,代碼來源:Helper.java

示例13: 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;
    }
 
開發者ID:YbrainInc,項目名稱:react-native-ble-quick-sdk,代碼行數:60,代碼來源:PeripheralExtension.java

示例14: 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;
    }
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:51,代碼來源:Helper.java


注:本文中的android.bluetooth.BluetoothGattCharacteristic.PROPERTY_WRITE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。