当前位置: 首页 > news >正文

陇南市网站建设_网站建设公司_H5网站_seo优化

网站域名交易,国外免费域名申请,网站排名优化推广厦门,新增域名网站建设方案BLE(Bluetooth Low Energy)低功耗蓝牙兴起的原因BLE蓝牙的兴起主要是因为可穿戴设备的流行#xff0c;由于传统蓝牙不能满足可穿戴设备的续航要求#xff0c;因此大部分可穿戴设备采用蓝牙4.0技术#xff0c;即BLE蓝牙技术。BLE的特点快速搜索、快速连接、超低功耗连接和数据…BLE(Bluetooth Low Energy)低功耗蓝牙兴起的原因BLE蓝牙的兴起主要是因为可穿戴设备的流行由于传统蓝牙不能满足可穿戴设备的续航要求因此大部分可穿戴设备采用蓝牙4.0技术即BLE蓝牙技术。BLE的特点快速搜索、快速连接、超低功耗连接和数据传输,但是数据传输速率低。在Android开发中BLE蓝牙一包数据最多20个字节因此在Android系统下最好不要使用BLE蓝牙传输大量的数据BLE蓝牙开发流程1、申请蓝牙权限注意在Android6.0以上需要打开位置不然搜索不到蓝牙设备2、获取蓝牙适配器判断本地蓝牙是否可用打开蓝牙/*获取蓝牙适配器*/mBluetoothManager (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);mBluetoothAdapter mBluetoothManager.getAdapter();/*** 判断蓝牙是否可用*/public boolean isBlueAdapterEnable() {return mBluetoothAdapter !null mBluetoothAdapter.isEnabled();}如果本地蓝牙未打开调用已下代码打开本地蓝牙/* 打开蓝牙适配器*/Intent intent new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);context.startActivityForResult(intent, 0);3、建立BluetoothAdapter.LeScanCall类的对象BluetoothAdapter.LeScanCallback scanCallback new BluetoothAdapter.LeScanCallback(){Overridepublic void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {//TODO处理搜索到的蓝牙设备逻辑}};4、搜索蓝牙设备mBluetoothAdapter .startLeScan(scanCallback);5、停止搜索蓝牙设备mBluetoothAdapter.stopLeScan(scanCallback)6、建立BluetoothGattCallBack类对象private BluetoothGattCallbackgattCallback new BluetoothGattCallback() {/* 断开或连接 状态发生变化时调用* */Overridepublic void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {super.onConnectionStateChange(gatt, status, newState);//连接成功if (newState BluetoothGatt.STATE_CONNECTED) {Log.i(TAG, 连接成功);gatt.discoverServices();}else {Log.i(TAG, 连接失败);connectedfalse;}}/* 发现设备(真正建立连接)*/Overridepublic void onServicesDiscovered(BluetoothGatt gatt, int status) {super.onServicesDiscovered(gatt, status);//直到这里才是真正建立了可通信的连接connectedture;//获取初始化服务和特征值mBluetoothGatt gatt;initServiceAndChara(mBluetoothGatt);//订阅通知mBluetoothGatt.setCharacteristicNotification(mBluetoothGatt.getService(NotifyUUID).getCharacteristic(NOTIFY_DESCRIPTOR), true);}/* 读操作的回调*/Overridepublic void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {super.onCharacteristicRead(gatt, characteristic, status);Log.e(TAG, onCharacteristicRead());}/* 写操作的回调*/Overridepublic void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {super.onCharacteristicWrite(gatt, characteristic, status);Log.e(TAG, onCharacteristicWrite()  status status ,value HexUtil.encodeHexStr(characteristic.getValue()));}/ * 接收到硬件返回的数据 */Overridepublic void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {super.onCharacteristicChanged(gatt, characteristic);Log.e(TAG,onCharacteristicChanged()characteristic.getValue());}};/*初始化mBlueGatt的服务和特征*/private void initServiceAndChara(BluetoothGatt mBluetoothGatt) {List bluetoothGattServices mBluetoothGatt.getServices();for (BluetoothGattService bluetoothGattService : bluetoothGattServices) {List characteristics bluetoothGattService.getCharacteristics();for (BluetoothGattCharacteristic characteristic : characteristics) {int charaProp characteristic.getProperties();if ((charaProp BluetoothGattCharacteristic.PROPERTY_NOTIFY) 0) {NotifyUUID bluetoothGattService.getUuid();NOTIFY_DESCRIPTOR characteristic.getUuid();}if ((charaProp BluetoothGattCharacteristic.PROPERTY_WRITE) 0) {bleWriteGattCharacteristic characteristic;}if ((charaProp BluetoothGattCharacteristic.PROPERTY_READ)0){bleReadGattCharacteristiccharacteristic;}Log.i(NOTIFY_DESCRIPTOR, NotifyUUID: NotifyUUID ,NOTIFY_DESCRIPTOR NOTIFY_DESCRIPTOR);}}}7、读取蓝牙数据public void readBleDeviceData(){if (connected mBluetoothGatt!null){mBluetoothGatt.readCharacteristic(bleReadGattCharacteristic);}}8、向蓝牙设备发送数据bleWriteGattCharacteristic.setValue(byte[] bytes);mBluetoothGatt.writeCharacteristic(bleWriteGattCharacteristic);9、断开蓝牙设备连接mBluetoothGatt.disconnect();
http://www.ihoyoo.com/news/30588.html

相关文章:

  • 网站优化服务回兴网络推广软件
  • 商城网站建设需要多少网站开发文件上传到服务器
  • 空间站天宫vr全景苏州建筑工程集团有限公司
  • 小型网站开发时间周期wordpress建网站详细教程
  • 汽车网站建设预算wordpress屏蔽功能org
  • 女性做网站很有名的网店美工名词解释
  • 广州建设厅电工网站校园微网站界面
  • 江桥网站建设六安门户网站建设哪家好
  • 广东网站优化公司商城网站开发模板
  • 做网站的工作有发展空间没有网推公司干什么的
  • 网站的程序有哪些内容自己做的小网站
  • iview可以做门户网站吗威海推广
  • wordpress 搬站appcms程序怎么做网站
  • 招聘网站模板页松滋网站定制
  • 淘宝上做淘宝客的网站家装公司网站建设方案
  • xwiki做的网站网页上视频如何下载
  • 如何用wordpress做企站中国建设执业资格注册管理中心网站
  • 辽宁天一建设有限责任公司网站高端设计公司名字大全
  • 某网站自己做中性笔公司在网上做网站怎么做账
  • 移动网站开发基础知识wordpress社交分享非插件
  • 公司网站建设服务费怎么做账wordpress 多博客
  • 盐城建设银行网站亿唐网不做网站做品牌
  • 十度网站建设佛山网站建设找千界
  • 自己电脑做网站域名备案在线ps网站
  • 快速搭建网站前端wordpress主题怎么改
  • 心理咨询网站建设论文想自己做网站需要会什么软件
  • 织梦网站logo怎么换项目管理系统开发
  • 网站建设行业淘宝装修模板在线教育
  • 如何修改网站源文件网站素材下载
  • 丽江市住房和城乡建设局网站建设工程项目报建网站