Android 蓝牙BLE 4.0 属性判断

    本文简单介绍如何判断蓝牙BLE4.0的 BluetoothGattCharacteristic 属性


    1、先看UUID定义;


    2、BluetoothGattCharacteristic的属性定义;

/**  
 * Characteristic proprty: Characteristic is broadcastable.  
 * 可以广播,二进制0001
 */   
public   static   final   int  PROPERTY_BROADCAST =  0x01 ;  
  
/**  
 * Characteristic property: Characteristic is readable.  
 * 可读,二进制0010
 */   
public   static   final   int  PROPERTY_READ =  0x02 ;  
  
/**  
 * Characteristic property: Characteristic can be written without response.  
 * 只可写,二进制0100
 */   
public   static   final   int  PROPERTY_WRITE_NO_RESPONSE =  0x04 ;  
  
/**  
 * Characteristic property: Characteristic can be written.  
 * 可写,二进制1000
 */   
public   static   final   int  PROPERTY_WRITE =  0x08 ;
  
/**  
 * Characteristic property: Characteristic supports notification  
 * 支持通知,二进制0001 0000
 */   
public   static   final   int  PROPERTY_NOTIFY =  0x10 ;  
  
/**  
 * Characteristic property: Characteristic supports indication  
 * 支持指示,二进制0010 0000
 */   
public   static   final   int  PROPERTY_INDICATE =  0x20 ;  
  
/**  
 * Characteristic property: Characteristic supports write with signature  
 * 支持写签名,二进制0100 0000
 */   
public   static   final   int  PROPERTY_SIGNED_WRITE =  0x40 ;  
  
/**  
 * Characteristic property: Characteristic has extended properties  
 * 可扩展属性,二进制1000 0000
 */   
public   static   final   int  PROPERTY_EXTENDED_PROPS =  0x80 ;  

    3、由二进制得出其属性由八个标志位表示,拥有的属性值是相加的,所以可以用 & 方法判断其属性;

		// 可读
		if ((charaProp & BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
			
		}
		// 可写,注:要 & 其可写的两个属性
		if ((charaProp & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0 
				|| (charaProp & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) {
			
		}
		// 可通知,可指示
		if ((charaProp & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0 
				|| (charaProp & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
			
		}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值