本文整理匯總了Java中android.bluetooth.BluetoothGattDescriptor.setValue方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattDescriptor.setValue方法的具體用法?Java BluetoothGattDescriptor.setValue怎麽用?Java BluetoothGattDescriptor.setValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGattDescriptor
的用法示例。
在下文中一共展示了BluetoothGattDescriptor.setValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setCharacteristicNotification
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
/**
* Enables or disables notification on a give characteristic.
*
* @param characteristic Characteristic to act on.
* @param enabled If true, enable notification. False otherwise.
*/
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
Log.d(TAG,"Notification set for " + characteristic.getUuid().toString() + " : " + String.valueOf(enabled));
// step 1 - enable notifications locally
boolean success = mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
if(!success) {
Log.e("------", "Seting proper notification status for characteristic failed!");
}
//step 2 - write to Clienc Characteristic Config Descriptor (2902) proper values
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
if(descriptor != null) {
// byte[] val = enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
byte[] val = enabled ? BluetoothGattDescriptor.ENABLE_INDICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
descriptor.setValue(val);
mBluetoothGatt.writeDescriptor(descriptor);
}
}
示例2: enableCharacteristicNotification
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
/**
* Enable or disable notifications/indications for a given characteristic.
*
* @param characteristic The characteristic for which to enable notifications.
* @param descriptor Bluetooth GATT descriptor.
* @param enable Enable or disable notification.
* @return Result of enabling notifications.
*/
public int enableCharacteristicNotification(BluetoothGattCharacteristic characteristic, BluetoothGattDescriptor
descriptor, boolean enable) {
if(gatt == null) {
return BLE_ERROR_NOOP;
}
int rc = BLE_ERROR_NOOP;
synchronized(locker) {
error = 0;
if(gatt.setCharacteristicNotification(characteristic, enable)) {
logi("characteristic notif success");
rc = error | bleState;
descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE :
BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
}
}
return writeDescriptor(descriptor) | rc;
}
示例3: setCharacteristicNotification
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
/**
* Enable or disable notifications/indications for a given characteristic.
*
* 是否允許刷新特征碼
*
* <p>Once notifications are enabled for a characteristic, a
* {@link BluetoothGattCallback#onCharacteristicChanged} callback will be
* triggered if the remote device indicates that the given characteristic
* has changed.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param characteristic The characteristic for which to enable notifications
* @param enable Set to true to enable notifications/indications
* @return true, if the requested notification status was set successfully
*/
public boolean setCharacteristicNotification(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
boolean enable) {
if (gatt != null && characteristic != null) {
BleLog.i(TAG, "Characteristic set notification value: " + enable);
/** 是否允許刷新特征碼獲取數據 */
boolean success = gatt.setCharacteristicNotification(characteristic, enable);
// This is specific to Heart Rate Measurement.(心率測量專用)
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
BleLog.i(TAG, "Heart Rate Measurement set [descriptor] notification value: " + enable);
BluetoothGattDescriptor descriptor = characteristic
.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
// 向描述符中寫入 'ENABLE_NOTIFICATION_VALUE'
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
}
return success;
}
return false;
}
示例4: setCharacteristicNotification
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
/**
* Enables or disables notification on a give characteristic.
*
* @param characteristic Characteristic to act on.
* @param enabled If true, enable notification. False otherwise.
*/
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
for(BluetoothGattDescriptor dp:descriptors){
dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(dp);
}
}
示例5: setCharacteristicNotification
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
private void setCharacteristicNotification(
@NonNull BluetoothGatt bluetoothgatt,
@NonNull BluetoothGattCharacteristic bluetoothgattcharacteristic,
boolean flag
) {
bluetoothgatt.setCharacteristicNotification(bluetoothgattcharacteristic, flag);
if (FIND_ME_CHARACTERISTIC.equals(bluetoothgattcharacteristic.getUuid())) {
BluetoothGattDescriptor descriptor = bluetoothgattcharacteristic.getDescriptor(
CLIENT_CHARACTERISTIC_CONFIG
);
if (descriptor != null) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bluetoothgatt.writeDescriptor(descriptor);
}
}
}
示例6: onServicesDiscovered
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.d(mTAG, "onServicesDiscovered");
if(status == BluetoothGatt.GATT_SUCCESS){
mGattnRF51822Service = gatt.getService(UUID_nRF51822_SERVICE_ID);
if(mGattnRF51822Service != null){
List<BluetoothGattCharacteristic> lstChars = mGattnRF51822Service.getCharacteristics();
for(BluetoothGattCharacteristic mCharacteristic : lstChars){
List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
BluetoothGattDescriptor mGattnRF51822Descriptor = mCharacteristic.getDescriptor(UUID_nRF51822_DESCRIPTOR_ID);
if(mGattnRF51822Descriptor != null && mCharacteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
gatt.setCharacteristicNotification(mCharacteristic, true);
byte[] mValue = {0x01, 0x00};
mGattnRF51822Descriptor.setValue(mValue);
gatt.writeDescriptor(mGattnRF51822Descriptor);
}
}
}
}
else{
gatt.close();
mIsConnecting = false;
}
}
示例7: onServicesDiscovered
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
boolean connected = false;
BluetoothGattService service = gatt.getService(SERVICE_UUID);
if (service != null) {
BluetoothGattCharacteristic characteristic = service.getCharacteristic(CHARACTERISTIC_COUNTER_UUID);
if (characteristic != null) {
gatt.setCharacteristicNotification(characteristic, true);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(DESCRIPTOR_CONFIG);
if (descriptor != null) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
connected = gatt.writeDescriptor(descriptor);
}
}
}
mListener.onConnected(connected);
} else {
Log.w(TAG, "onServicesDiscovered received: " + status);
}
}
示例8: enableNotifications
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public final boolean enableNotifications(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_NOTIFY) == 0)
return false;
gatt.setCharacteristicNotification(characteristic, true);
final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
if (descriptor != null) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
return gatt.writeDescriptor(descriptor);
}
return false;
}
示例9: enableIndications
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public final boolean enableIndications(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_INDICATE) == 0)
return false;
gatt.setCharacteristicNotification(characteristic, true);
final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
if (descriptor != null) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
return gatt.writeDescriptor(descriptor);
}
return false;
}
示例10: setCharacteristicIndication
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
private void setCharacteristicIndication(BluetoothGattCharacteristic characteristic, boolean enabled)
{
if ( mBluetoothAdapter == null || mBluetoothGatt == null )
{
NLog.d("BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor desc = characteristic.getDescriptor(CONFIG_DESCRIPTOR);
if ( (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) == BluetoothGattCharacteristic.PROPERTY_INDICATE )
{
// Enabled remote indication
desc.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
}
else if ( (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY)
{
desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
}
else
{
NLog.d("Error : Characteristic is not notify or indicate");
return;
}
mBluetoothGatt.writeDescriptor(desc);
}
示例11: setCharacteristicNotification
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
/**
* 請求BLE設備獲取數據
* mGatt.setCharacteristicNotification(characteristic, true) 設置允許接收BLE設備返回的數據
*
* @param service 服務碼
* @param chara 特征碼
* @param desc
* @param enable
*/
public void setCharacteristicNotification(UUID service, UUID chara, UUID desc, boolean enable) {
BluetoothGattCharacteristic characteristic = mGatt.getService(service).getCharacteristic(chara);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(desc);
if (enable) {
mGatt.setCharacteristicNotification(characteristic, true);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);
} else {
mGatt.setCharacteristicNotification(characteristic, false);
descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);
}
}
示例12: createService
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public BluetoothGattService createService() {
BluetoothGattService bluetoothgattservice = new BluetoothGattService(WATCH_CTRL_SERVICE_UUID, 0);
BluetoothGattCharacteristic bluetoothgattcharacteristic = new BluetoothGattCharacteristic(KEY_CONTAINER_CHARACTERISTIC_UUID, 4, 16);
bluetoothgattcharacteristic.setValue(new byte[0]);
BluetoothGattCharacteristic bluetoothgattcharacteristic1 = new BluetoothGattCharacteristic(NAME_OF_APP_CHARACTERISTIC_UUID, 2, 3);
bluetoothgattcharacteristic1.setValue(READY_MESSAGE.getBytes());
BluetoothGattDescriptor bluetoothgattdescriptor = new BluetoothGattDescriptor(CCC_DESCRIPTOR_UUID, 17);
bluetoothgattdescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bluetoothgattcharacteristic1.addDescriptor(bluetoothgattdescriptor);
bluetoothgattservice.addCharacteristic(bluetoothgattcharacteristic);
bluetoothgattservice.addCharacteristic(bluetoothgattcharacteristic1);
return bluetoothgattservice;
}
示例13: setDescriptorValue
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public boolean setDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid, byte[] value){
BluetoothGattService service = gattServer.getService(serviceUuid);
if(service == null)
return false;
BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
if(characteristic == null)
return false;
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
if(descriptor == null)
return false;
return descriptor.setValue(value);
}
示例14: setDescriptorValue
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public boolean setDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid, byte[] value){
if(gattConnection == null)
return false;
BluetoothGattService service = gattConnection.getService(serviceUuid);
if(service == null)
return false;
BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
if(characteristic == null)
return false;
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
if(descriptor == null)
return false;
descriptor.setValue(value);
return gattConnection.writeDescriptor(descriptor);
}
示例15: receiveNotifications
import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public void receiveNotifications(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid, boolean receive){
BluetoothGattCharacteristic characteristic = getCharacteristic(serviceUuid, characteristicUuid);
gattConnection.setCharacteristicNotification(characteristic, receive);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gattConnection.writeDescriptor(descriptor);
}