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


Java BluetoothGattDescriptor.getValue方法代码示例

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


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

示例1: getView

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
@Override
public View getView(int position, View view, ViewGroup parent) {
    final ViewHolder viewHolder;
    // General ListView optimization code.
    if (view == null) {
        view = mInflater.inflate(R.layout.list_item, null);
        viewHolder = new ViewHolder();
        viewHolder.descUuid = (TextView) view.findViewById(R.id.tv_item2);
        viewHolder.descValue = (TextView) view.findViewById(R.id.tv_item1);
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    BluetoothGattDescriptor desc = (BluetoothGattDescriptor) getItem(position);
    viewHolder.descUuid.setText("uuid: " + desc.getUuid().toString().substring(4, 8));
    if (desc.getValue() != null && desc.getValue().length > 0) {
        viewHolder.descValue.setText("Name:" + GattAttributeResolver.getAttributeName(desc.getUuid().toString(), mContext.getString(R.string.unknown))
                + "\n" + "Value:" + ByteUtils.byteArrayToHexString(desc.getValue()));
    } else {
        viewHolder.descValue.setText("Name:" + GattAttributeResolver.getAttributeName(desc.getUuid().toString(), mContext.getString(R.string.unknown)));
    }
    return view;
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:25,代码来源:DescListAdapter.java

示例2: onCharacteristicChanged

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
@Override
public final void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
	final String data = ParserUtils.parse(characteristic);

	if (isBatteryLevelCharacteristic(characteristic)) {
		Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
		final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
		Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
		mCallbacks.onBatteryValueReceived(batteryValue);
	} else {
		final BluetoothGattDescriptor cccd = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
		final boolean notifications = cccd == null || cccd.getValue() == null || cccd.getValue().length != 2 || cccd.getValue()[0] == 0x01;

		if (notifications) {
			Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
			onCharacteristicNotified(gatt, characteristic);
		} else { // indications
			Logger.i(mLogSession, "Indication received from " + characteristic.getUuid() + ", value: " + data);
			onCharacteristicIndicated(gatt, characteristic);
		}
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:23,代码来源:BleManager.java

示例3: onDescriptorRead

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
@Override
public void onDescriptorRead(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        if (CLIENT_CHARACTERISTIC_CONFIG.equals(descriptor.getUuid())) {
            if (SERVICE_CHANGED_UUID.equals(descriptor.getCharacteristic().getUuid())) {
                // We have enabled indications for the Service Changed characteristic
                mServiceChangedIndicationsEnabled = descriptor.getValue()[0] == 2;
                mRequestCompleted = true;
            }
        }
    } else {
        loge("Descriptor read error: " + status);
        mError = ERROR_CONNECTION_MASK | status;
    }
    // Notify waiting thread
    synchronized (mLock) {
        mLock.notifyAll();
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:20,代码来源:DfuBaseService.java

示例4: onDescriptorWrite

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
@Override
public void onDescriptorWrite(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {

    if (status == BluetoothGatt.GATT_SUCCESS) {
        if (CLIENT_CHARACTERISTIC_CONFIG.equals(descriptor.getUuid())) {
            if (SERVICE_CHANGED_UUID.equals(descriptor.getCharacteristic().getUuid())) {
                // We have enabled indications for the Service Changed characteristic
                mServiceChangedIndicationsEnabled = descriptor.getValue()[0] == 2;
            } else {
                // We have enabled notifications for this characteristic
                mNotificationsEnabled = descriptor.getValue()[0] == 1;
            }
        }
    } else {
        loge("Descriptor write error: " + status);
        mError = ERROR_CONNECTION_MASK | status;
    }
    // Notify waiting thread
    synchronized (mLock) {
        mLock.notifyAll();
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:23,代码来源:DfuBaseService.java

示例5: getDescriptorValue

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
public byte[] getDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return descriptor.getValue();
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEServer.java

示例6: getDescriptorValueString

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
public String getDescriptorValueString(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return new String(descriptor.getValue());
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEServer.java

示例7: getDescriptorValue

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
public byte[] getDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return descriptor.getValue();
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEClient.java

示例8: getDescriptorValueString

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
public String getDescriptorValueString(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return new String(descriptor.getValue());
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEClient.java

示例9: onDescriptorWrite

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
@Override
public final void onDescriptorWrite(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
	if (status == BluetoothGatt.GATT_SUCCESS) {
		Logger.i(mLogSession, "Data written to descr. " + descriptor.getUuid() + ", value: " + ParserUtils.parse(descriptor));

		if (isServiceChangedCCCD(descriptor)) {
			Logger.a(mLogSession, "Service Changed notifications enabled");
			if (!readBatteryLevel())
				nextRequest();
		} else if (isBatteryLevelCCCD(descriptor)) {
			final byte[] value = descriptor.getValue();
			if (value != null && value.length > 0 && value[0] == 0x01) {
				Logger.a(mLogSession, "Battery Level notifications enabled");
				nextRequest();
			} else
				Logger.a(mLogSession, "Battery Level notifications disabled");
		} else {
			nextRequest();
		}
	} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
		if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
			DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
			mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
		}
	} else {
		DebugLogger.e(TAG, "onDescriptorWrite error " + status);
		onError(ERROR_WRITE_DESCRIPTOR, status);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:30,代码来源:BleManager.java

示例10: isNotificationEnabled

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
public boolean isNotificationEnabled(String mac, BluetoothGattCharacteristic characteristic) {
    BluetoothGatt bluetoothGatt = checkAndGetGattItem(mac);
    boolean result = false;
    if (bluetoothGatt != null) {
        BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(GattInfo.CLIENT_CHARACTERISTIC_CONFIG);
        if (clientConfig != null) {
            result = clientConfig.getValue() == BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
        }
    }
    return result;
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:12,代码来源:UdooBluService.java

示例11: asWritableMap

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的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;
	}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:56,代码来源:Peripheral.java

示例12: displayGattServices

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的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));
                }
            }
        }
    }//

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

示例13: start

import android.bluetooth.BluetoothGattDescriptor; //导入方法依赖的package包/类
@Override
protected void start(Connection connection, BluetoothGatt gatt) {
    if (type == Type.UNSUBSCRIBE && connection.getCharacteristicsChangedListenerCount(characteristicUUID) > 0) {
        NeatleLogger.d("Won't unsubscribe on " + characteristicUUID + " since it has registered listeners");
        finish(CommandResult.createEmptySuccess(characteristicUUID));
        return;
    }

    BluetoothGattService service = gatt.getService(serviceUUID);
    if (service == null) {
        finish(CommandResult.createErrorResult(characteristicUUID, SERVICE_NOT_FOUND));
        return;
    }

    BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUUID);
    if (characteristic == null) {
        finish(CommandResult.createErrorResult(characteristicUUID, CHARACTERISTIC_NOT_FOUND));
        return;
    }

    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
    if (descriptor == null) {
        finish(CommandResult.createErrorResult(characteristicUUID, DESCRIPTOR_NOT_FOUND));
        return;
    }

    boolean turnOn;
    byte[] valueToWrite;
    switch (type) {
        case Type.SUBSCRIBE_INDICATION:
            NeatleLogger.d("Subscribing to indications on  " + characteristicUUID);
            valueToWrite = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;
            turnOn = true;
            break;
        case Type.SUBSCRIBE_NOTIFICATION:
            NeatleLogger.d("Subscribing to notifications on  " + characteristicUUID);
            valueToWrite = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
            turnOn = true;
            break;
        case Type.UNSUBSCRIBE:
            NeatleLogger.d("Unsubscribing from notifications/indications on  " + characteristicUUID);
            valueToWrite = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
            turnOn = false;
            break;
        default:
            throw new IllegalStateException();
    }

    byte[] descriptorValue = descriptor.getValue();
    if (Arrays.equals(descriptorValue, valueToWrite)) {
        NeatleLogger.d("No subscription changes needed - is at  " + valueToWrite[0] + " on " + characteristicUUID);
        finish(CommandResult.createEmptySuccess(characteristicUUID));
        return;
    }

    if (!gatt.setCharacteristicNotification(characteristic, turnOn)) {
        NeatleLogger.e("Failed to change characteristics notification flag on " + characteristicUUID);
        finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
        return;
    }

    descriptor.setValue(valueToWrite);
    NeatleLogger.e("Writing descriptor on " + characteristicUUID);
    if (!gatt.writeDescriptor(descriptor)) {
        NeatleLogger.e("Failed to write descriptor on " + characteristicUUID);
        finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:69,代码来源:SubscribeCommand.java


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