本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.getDescriptors方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.getDescriptors方法的具體用法?Java BluetoothGattCharacteristic.getDescriptors怎麽用?Java BluetoothGattCharacteristic.getDescriptors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.getDescriptors方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCharacteristicChanged
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的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;
}
}
示例2: setCharacteristicNotification
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的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);
}
}
示例3: onServicesDiscovered
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的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;
}
}
示例4: setCharacteristicNotification
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
if (bluetoothAdapter == null || bluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
bluetoothGatt.setCharacteristicNotification(characteristic, enabled);
for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
descriptor.setValue(
enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] {0x00, 0x00});
bluetoothGatt.writeDescriptor(descriptor);
}
}
示例5: printServices
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
* 打印所有的service, 特征嗎, 描述符
* 在service被發現後, 可以調用
* @param gatt
*/
public static void printServices(BluetoothGatt gatt) {
if (gatt != null) {
for (BluetoothGattService service : gatt.getServices()) {
BleLog.i(TAG, "service: " + service.getUuid());
for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
BleLog.d(TAG, " characteristic: " + characteristic.getUuid() + " value: " + Arrays.toString(characteristic.getValue()));
for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
BleLog.v(TAG, " descriptor: " + descriptor.getUuid() + " value: " + Arrays.toString(descriptor.getValue()));
}
}
}
}
}
示例6: asWritableMap
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public WritableMap asWritableMap(BluetoothGatt gatt) {
WritableMap map = asWritableMap();
WritableArray servicesArray = Arguments.createArray();
WritableArray characteristicsArray = Arguments.createArray();
if (connected && gatt != null) {
for (BluetoothGattService service : gatt.getServices()) {
WritableMap serviceMap = Arguments.createMap();
serviceMap.putString("uuid", UUIDHelper.uuidToString(service.getUuid()));
for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
WritableMap characteristicsMap = Arguments.createMap();
characteristicsMap.putString("service", UUIDHelper.uuidToString(service.getUuid()));
characteristicsMap.putString("characteristic", UUIDHelper.uuidToString(characteristic.getUuid()));
characteristicsMap.putMap("properties", Helper.decodeProperties(characteristic));
if (characteristic.getPermissions() > 0) {
characteristicsMap.putMap("permissions", Helper.decodePermissions(characteristic));
}
WritableArray descriptorsArray = Arguments.createArray();
for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
WritableMap descriptorMap = Arguments.createMap();
descriptorMap.putString("uuid", UUIDHelper.uuidToString(descriptor.getUuid()));
if (descriptor.getValue() != null)
descriptorMap.putString("value", Base64.encodeToString(descriptor.getValue(), Base64.NO_WRAP));
else
descriptorMap.putString("value", null);
if (descriptor.getPermissions() > 0) {
descriptorMap.putMap("permissions", Helper.decodePermissions(descriptor));
}
descriptorsArray.pushMap(descriptorMap);
}
if (descriptorsArray.size() > 0) {
characteristicsMap.putArray("descriptors", descriptorsArray);
}
characteristicsArray.pushMap(characteristicsMap);
}
servicesArray.pushMap(serviceMap);
}
map.putArray("services", servicesArray);
map.putArray("characteristics", characteristicsArray);
}
return map;
}
示例7: displayGattServices
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void displayGattServices(List<BluetoothGattService> gattServices) {
if (gattServices == null) return;
for (BluetoothGattService gattService : gattServices) {
//-----Service的字段信息-----//
int type = gattService.getType();
Log.e(TAG,"-->service type:"+Utils.getServiceType(type));
Log.e(TAG,"-->includedServices size:"+gattService.getIncludedServices().size());
Log.e(TAG,"-->service uuid:"+gattService.getUuid());
//-----Characteristics的字段信息-----//
List<BluetoothGattCharacteristic> gattCharacteristics =gattService.getCharacteristics();
for (final BluetoothGattCharacteristic gattCharacteristic: gattCharacteristics) {
Log.e(TAG,"---->char uuid:"+gattCharacteristic.getUuid());
int permission = gattCharacteristic.getPermissions();
Log.e(TAG,"---->char permission:"+Utils.getCharPermission(permission));
int property = gattCharacteristic.getProperties();
Log.e(TAG,"---->char property:"+Utils.getCharPropertie(property));
byte[] data = gattCharacteristic.getValue();
if (data != null && data.length > 0) {
Log.e(TAG,"---->char value:"+new String(data));
}
if(gattCharacteristic.getUuid().toString().equals(UUID_RESPONSE)) {
ResponseCharac = gattCharacteristic;
}
//UUID_KEY_DATA是可以跟藍牙模塊串口通信的Characteristic
if(gattCharacteristic.getUuid().toString().equals(UUID_REQUEST)){
//測試讀取當前Characteristic數據,會觸發mOnDataAvailable.onCharacteristicRead()
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mBLE.readCharacteristic(gattCharacteristic);
mHandler.postDelayed(this, 500);
mBLE.readRemoteRssi();
//BluetoothGattDescriptor descriptor = gattCharacteristic.getDescriptor(HD_Profile.UUID_CHAR_NOTIFY_DIS)
}
}, 500);
//接受Characteristic被寫的通知,收到藍牙模塊的數據後會觸發mOnDataAvailable.onCharacteristicWrite()
mBLE.setCharacteristicNotification(gattCharacteristic, true);
//設置數據內容
//gattCharacteristic.setValue("hi");
//往藍牙模塊寫入數據
// mBLE.writeCharacteristic(gattCharacteristic);
}
//-----Descriptors的字段信息-----//
List<BluetoothGattDescriptor> gattDescriptors = gattCharacteristic.getDescriptors();
for (BluetoothGattDescriptor gattDescriptor : gattDescriptors) {
Log.e(TAG, "-------->desc uuid:" + gattDescriptor.getUuid());
int descPermission = gattDescriptor.getPermissions();
Log.e(TAG,"-------->desc permission:"+ Utils.getDescPermission(descPermission));
byte[] desData = gattDescriptor.getValue();
if (desData != null && desData.length > 0) {
Log.e(TAG, "-------->desc value:"+ new String(desData));
}
}
}
}//
}