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


Java BluetoothGattDescriptor类代码示例

本文整理汇总了Java中android.bluetooth.BluetoothGattDescriptor的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGattDescriptor类的具体用法?Java BluetoothGattDescriptor怎么用?Java BluetoothGattDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BluetoothGattDescriptor类属于android.bluetooth包,在下文中一共展示了BluetoothGattDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCharacteristicChanged

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    Log.d(mTAG, "onCharacteristicChanged");
    byte[] mValue = characteristic.getValue();
    if(characteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
        mAirTemperature = (mValue[0] << 8 | mValue[1])/10;
        gatt.setCharacteristicNotification(characteristic, false);
        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_LIGHT)){
                gatt.setCharacteristicNotification(mCharacteristic, true);
                byte[] mDesValue = {0x01, 0x00};
                mGattnRF51822Descriptor.setValue(mDesValue);
                gatt.writeDescriptor(mGattnRF51822Descriptor);
            }
        }
    }
    else if(characteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
        mLight = (mValue[0] << 8 | mValue[1]);
        gatt.close();
        Log.d(mTAG, "onCharacteristicChanged data=" + getData());
        mIsConnecting = false;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:27,代码来源:nRF51822SensorEntity.java

示例2: onDescriptorWrite

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
    Log.i(TAG, "onDescriptorWrite: " + status);
    descriptorWriteQueue.remove();  //pop the item that we just finishing writing
    //if there is more to write, do it!
    if(descriptorWriteQueue.size() > 0) {
        gatt.writeDescriptor(descriptorWriteQueue.element());
    } else if(characteristicReadQueue.size() > 0) {
        gatt.readCharacteristic(characteristicReadQueue.element());
    }
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:12,代码来源:BluetoothUtilImpl.java

示例3: handleDescriptorReadCallback

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
/**
 * 读描述符
 * @param bleCallback
 */
private void handleDescriptorReadCallback(final BleDescriptorCallback bleCallback) {
    if (bleCallback != null) {
        listenAndTimer(bleCallback, MSG_READ_DES, new BluetoothGattCallback() {
            AtomicBoolean msgRemoved = new AtomicBoolean(false);

            @Override
            public void onDescriptorRead(BluetoothGatt gatt,
                                         BluetoothGattDescriptor descriptor, int status) {
                if (!msgRemoved.getAndSet(true)) {
                    handler.removeMessages(MSG_READ_DES, this);
                }
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    bleCallback.onSuccess(descriptor);
                } else {
                    bleCallback.onFailure(new GattException(status));
                }
            }
        });
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:25,代码来源:LiteBleConnector.java

示例4: getSupportedGattServices

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
public List<BluetoothGattService> getSupportedGattServices() {
    if (mBluetoothGatt == null) {
        return null;
    }

    List<BluetoothGattService> gattServices = mBluetoothGatt.getServices();

    for (BluetoothGattService gattService : gattServices) {
        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            String uuid = gattCharacteristic.getUuid().toString();
            if(uuid.equalsIgnoreCase(UUID_NOTIFY.toString())){
                mNotifyCharacteristic = gattCharacteristic;
                mBluetoothGatt.setCharacteristicNotification(gattCharacteristic, true);
                ULog.i("setCharacteristicNotification : " + uuid);
                BluetoothGattDescriptor descriptor = gattCharacteristic
                        .getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                mBluetoothGatt.writeDescriptor(descriptor);
            }
        }
    }
    return gattServices;
}
 
开发者ID:WillFlower,项目名称:BluetoothCtrl,代码行数:25,代码来源:BluetoothLeService.java

示例5: 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

示例6: BLEServer

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
public BLEServer(Context context, BLEServerDelegate delegate){
	this.context = context;
	this.delegate = delegate;
	if(this.delegate == null){
		this.delegate = new BLEServerDelegate() {
			@Override
			public void onAdvertise(AdvertiseError error) {}
			@Override
			public void onDeviceConnected(BluetoothDevice device) {}
			@Override
			public void onDeviceDisconnected(BluetoothDevice device) {}
			@Override
			public void onCharacteristicChangedServer(BluetoothGattCharacteristic characteristic) {}
			@Override
			public void onDescriptorChanged(BluetoothGattDescriptor descriptor) {}
		};
	}
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:19,代码来源:BLEServer.java

示例7: onDescriptorReadRequest

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
@Override
public void onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset,
                                    BluetoothGattDescriptor descriptor) {
    if (TimeProfile.CLIENT_CONFIG.equals(descriptor.getUuid())) {
        Log.d(TAG, "Config descriptor read");
        byte[] returnValue;
        if (mRegisteredDevices.contains(device)) {
            returnValue = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
        } else {
            returnValue = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
        }
        mBluetoothGattServer.sendResponse(device,
                requestId,
                BluetoothGatt.GATT_FAILURE,
                0,
                returnValue);
    } else {
        Log.w(TAG, "Unknown descriptor read request");
        mBluetoothGattServer.sendResponse(device,
                requestId,
                BluetoothGatt.GATT_FAILURE,
                0,
                null);
    }
}
 
开发者ID:androidthings,项目名称:sample-bluetooth-le-gattserver,代码行数:26,代码来源:GattServerActivity.java

示例8: 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

示例9: 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

示例10: onDescriptorWriteRequest

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
@Override
public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
    if (DESCRIPTOR_CONFIG.equals(descriptor.getUuid())) {
        if (Arrays.equals(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, value)) {
            Log.d(TAG, "Subscribe device to notifications: " + device);
            mRegisteredDevices.add(device);
        } else if (Arrays.equals(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE, value)) {
            Log.d(TAG, "Unsubscribe device from notifications: " + device);
            mRegisteredDevices.remove(device);
        }

        if (responseNeeded) {
            mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null);
        }
    } else {
        Log.w(TAG, "Unknown descriptor write request");
        if (responseNeeded) {
            mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_FAILURE, 0, null);
        }
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:22,代码来源:GattServer.java

示例11: 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

示例12: 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

示例13: onDescriptorWriteRequest

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
@Override
public void onDescriptorWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattDescriptor descriptor, final boolean preparedWrite, final boolean responseNeeded, final int offset, final byte[] value) {
    super.onDescriptorWriteRequest(device, requestId, descriptor, preparedWrite, responseNeeded, offset, value);
    Log.d(TAG, "onDescriptorWriteRequest descriptor: " + descriptor.getUuid() + ", value: " + Arrays.toString(value) + ", responseNeeded: " + responseNeeded + ", preparedWrite: " + preparedWrite);

    descriptor.setValue(value);

    if (responseNeeded) {
        if (BleUuidUtils.matches(DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION, descriptor.getUuid())) {
            // send empty
            if (gattServer != null) {
                gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, EMPTY_BYTES);
            }
        }
    }
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:17,代码来源:HidPeripheral.java

示例14: enableNotifications

import android.bluetooth.BluetoothGattDescriptor; //导入依赖的package包/类
/**
 * Enables notifications on given characteristic
 *
 * @return true is the request has been sent, false if one of the arguments was <code>null</code> or the characteristic does not have the CCCD.
 */
protected 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;

	Logger.d(mLogSession, "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
	gatt.setCharacteristicNotification(characteristic, true);
	final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
	if (descriptor != null) {
		descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
		Logger.v(mLogSession, "Enabling notifications for " + characteristic.getUuid());
		Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x01-00)");
		return gatt.writeDescriptor(descriptor);
	}
	return false;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:27,代码来源:BleManager.java

示例15: 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


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