关于蓝牙开发,必须注意的广播

/**有注释的广播,蓝牙连接时都会用到

* bind一般会停止搜索ACTION_DISCOVERY_FINISHED

* @param cxt

*/

intentFilter.addAction(BluetoothDevice.ACTION_FOUND); //搜索蓝压设备,每搜到一个设备发送一条广播

intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); //配对开始时,配对成功时

intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); //配对时,发起连接

intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);

intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); //配对结束时,断开连接

intentFilter.addAction(PAIRING_REQUEST); //配对请求

(android.bluetooth.device.action.PAIRING_REQUEST)

intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);//开始搜索

intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); //搜索结束。重新搜索时,会先终止搜索

intentFilter.addAction(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);//连接蓝牙,断开蓝牙 

intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);

intentFilter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);//更改蓝牙名称,打开蓝牙时,可能会调用多次

intentFilter.addAction(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

intentFilter.addAction(BluetoothAdapter.ACTION_REQUEST_ENABLE);

intentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);//搜索模式改变


蓝牙开发,如果考虑到错误的断开蓝牙,unbind,等情况,必须注册好以上的蓝牙广播,其中,PAIRING_REQUEST,是android隐藏的广播,涉及到跳过bind弹框,直接pin,配对,必须要注册。

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
概述GENERAL 1.1 适用范围 APPLICATION 此规格书适用于机械式轻触开关的相关要求 This specification is applied to the requirements for TACTILE SWITCH (MECHANICAL CONTACT) 1.2 工作温度范围 Operating Temperature Range -20℃~80℃(在标准大气压、标准湿度条件下) -20℃~80℃(Normal humidity, normal air pressure) 1.3 贮藏温度范围 Storage Temperature Range -20℃~80℃(在标准大气压、标准湿度条件下) -20℃~80℃(Normal humidity, normal air pressure) 1.4 测试条件 Test Conditions 在没有其它特定的条件下,应该在以下的条件下进行测试和测量: Unless otherwise specified, tests and measurement shall be made in the following standard conditions: 常温…………………………………5℃~35℃ Normal temperature………………5℃~35℃ 标准湿度……………………………相对湿度25%~85% Normal humidity…………………relative humidity 25%~85% 标准大气压…………………………86KPa~106Kpa Normal air pressure…………………86Kpa~106Kpa 在制造过程中,测试和测量应该在以下的条件下进行: If any doubt arise from the judgment, tests shall be conducted at the following conditions: 温度…………………………………20℃±2℃ Temperature………………………20℃±2℃ 相对湿度……………………………65%±5% Relative humidity………………65%±5% 环境气压…………………………86KPa~106Kpa Air pressure…………………………86KPa~106Kpa2、 详细说明 Detailed specification 2.1 外观:应无影响、降低产品性能的缺陷; Appearance: There should be no defects that affect the serviceability of product. 2.2 结构尺寸和安装尺寸:应符合装配图要求 Style and dimension: shall conform to the assemble drawings. 2.3 操作形式:有触觉反应的操作 Type of actuating: Tactile feedback. 2.4 开关结构:单回路单输出(具体的触点结构在装配图中已绘出); Contact arrangement: 1 pole, 1 throw (Details of contact arrangement are given in the assembly drawings.) 2.5 开关工作额定值:DC 12V,50mA(有效值) DC 12V,50mA (最大额定值) DC 1V,10μA (最小额定值) Ratings: 12V DC, 50mA (effective value) 12V DC, 50mA (maximum) 1V DC,10μA (minimum) 3、 电气性能: ELECTRICAL SPECIFICATION
在uniapp原生开发中,可以使用Android或iOS的原生API来实现监听蓝牙广播。以下是Android和iOS平台的实现方法: 1. Android平台 在Android平台上,可以使用Android蓝牙开发包(Android Bluetooth Low Energy)来实现监听蓝牙广播。具体步骤如下: (1)在AndroidManifest.xml文件中添加蓝牙权限和服务声明: ``` <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <service android:name=".BluetoothLEService" android:enabled="true" android:exported="true" /> ``` (2)创建一个继承自BluetoothGattCallback的类,并在其中实现onScanResult()方法监听蓝牙广播信息: ``` public class BluetoothLECallback extends BluetoothGattCallback { @Override public void onScanResult(int callbackType, ScanResult result) { // 处理蓝牙广播信息 } } ``` (3)在需要监听蓝牙广播的页面中,创建一个BluetoothAdapter实例,并通过BluetoothAdapter.startLeScan()方法开始扫描蓝牙设备。同时,将BluetoothLECallback实例传入BluetoothAdapter.startLeScan()方法中,以便在收到蓝牙广播时回调onScanResult()方法处理广播信息。示例代码如下: ``` private BluetoothAdapter mBluetoothAdapter; private BluetoothLECallback mBluetoothLECallback; // 初始化蓝牙适配器和回调实例 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothLECallback = new BluetoothLECallback(); // 开始扫描蓝牙设备 mBluetoothAdapter.startLeScan(mBluetoothLECallback); ``` 在上面的代码中,我们创建了一个BluetoothAdapter实例和一个BluetoothLECallback实例,并通过mBluetoothAdapter.startLeScan()方法开始扫描蓝牙设备。当扫描到蓝牙设备时,会回调mBluetoothLECallback.onScanResult()方法,我们可以在该方法中处理蓝牙广播信息。 2. iOS平台 在iOS平台上,可以使用CoreBluetooth框架来实现监听蓝牙广播。具体步骤如下: (1)在Info.plist文件中添加蓝牙权限声明: ``` <key>NSBluetoothPeripheralUsageDescription</key> <string>需要使用蓝牙功能来连接设备</string> ``` (2)创建一个继承自CBCentralManagerDelegate的类,并在其中实现centralManager(_:didDiscover:advertisementData:rssi:)方法监听蓝牙广播信息: ``` class BluetoothLEDelegate: NSObject, CBCentralManagerDelegate { func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { // 处理蓝牙广播信息 } } ``` (3)在需要监听蓝牙广播的页面中,创建一个CBCentralManager实例,并将BluetoothLEDelegate实例传入CBCentralManager.init()方法中,以便在收到蓝牙广播时回调centralManager(_:didDiscover:advertisementData:rssi:)方法处理广播信息。示例代码如下: ``` private var centralManager: CBCentralManager! private var bluetoothLEDelegate: BluetoothLEDelegate! // 初始化中心管理器和回调实例 bluetoothLEDelegate = BluetoothLEDelegate() centralManager = CBCentralManager(delegate: bluetoothLEDelegate, queue: nil) // 开始扫描蓝牙设备 centralManager.scanForPeripherals(withServices: nil, options: nil) ``` 在上面的代码中,我们创建了一个CBCentralManager实例和一个BluetoothLEDelegate实例,并通过centralManager.scanForPeripherals()方法开始扫描蓝牙设备。当扫描到蓝牙设备时,会回调bluetoothLEDelegate.centralManager(_:didDiscover:advertisementData:rssi:)方法,我们可以在该方法中处理蓝牙广播信息。 以上就是在uniapp原生开发中实现监听蓝牙广播的方法。需要注意的是,Android和iOS平台的实现方法略有不同,需要根据实际情况进行选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值