当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGattDescriptor.setValue方法代码示例

本文整理汇总了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);
        }
    }
 
开发者ID:smartlockpicking,项目名称:hackmelock-android,代码行数:30,代码来源:BluetoothLeService.java

示例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;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:30,代码来源:BLEManager.java

示例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;
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:39,代码来源:LiteBleConnector.java

示例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);
    }




}
 
开发者ID:haoyifan,项目名称:BLE-PEPS,代码行数:25,代码来源:BluetoothLeClass.java

示例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);
    }
  }
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:17,代码来源:BleService.java

示例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;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:25,代码来源:nRF51822SensorEntity.java

示例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);
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:24,代码来源:GattClient.java

示例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;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:20,代码来源:BleManager.java

示例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;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:20,代码来源:BleManager.java

示例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);
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:28,代码来源:BTLEAdt.java

示例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);
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:23,代码来源:BleManager.java

示例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;
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:15,代码来源:WatchCtrlService.java

示例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);
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEServer.java

示例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);
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:16,代码来源:BLEClient.java

示例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);
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:8,代码来源:BLEClient.java


注:本文中的android.bluetooth.BluetoothGattDescriptor.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。