App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-09-21 32383daed1b498577da8c37145e66e2a93e28b2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="HandheldFriendly" content="true">
<meta name="MobileOptimized" content="320">
<title>Bluetooth Document</title>
<link rel="stylesheet" type="text/css" href="res/doc.css" charset="utf-8">
<link rel="stylesheet" type="text/css" href="res/prettify.sons.css" charset="utf-8">
<script type="text/javascript" src="res/doc.js" charset="utf-8"></script><script type="text/javascript" src="res/prettify.js" charset="utf-8"></script>
</head>
<body><div id="content" class="content">
<h1><a name="plus.bluetooth">bluetooth</a></h1>
<p>
Bluetooth模块用于管理蓝牙设备,搜索附近蓝牙设备、实现简单数据传输等。</p>
<h2>方法:</h2>
<ul>
<li>
<a href="#plus.bluetooth.closeBluetoothAdapter">closeBluetoothAdapter</a>: 关闭蓝牙模块</li>
<li>
<a href="#plus.bluetooth.getBluetoothAdapterState">getBluetoothAdapterState</a>: 获取本机蓝牙适配器状态</li>
<li>
<a href="#plus.bluetooth.getBluetoothDevices">getBluetoothDevices</a>: 获取已搜索到的蓝牙设备</li>
<li>
<a href="#plus.bluetooth.getConnectedBluetoothDevices">getConnectedBluetoothDevices</a>: 根据uuid获取处于已连接的设备</li>
<li>
<a href="#plus.bluetooth.onBluetoothAdapterStateChange">onBluetoothAdapterStateChange</a>: 监听蓝牙适配器状态变化事件</li>
<li>
<a href="#plus.bluetooth.onBluetoothDeviceFound">onBluetoothDeviceFound</a>: 监听搜索到新设备的事件</li>
<li>
<a href="#plus.bluetooth.openBluetoothAdapter">openBluetoothAdapter</a>: 初始化蓝牙模块</li>
<li>
<a href="#plus.bluetooth.startBluetoothDevicesDiscovery">startBluetoothDevicesDiscovery</a>: 开始搜索附近的蓝牙设备</li>
<li>
<a href="#plus.bluetooth.stopBluetoothDevicesDiscovery">stopBluetoothDevicesDiscovery</a>: 停止搜寻附近的蓝牙外围设备</li>
<li>
<a href="#plus.bluetooth.closeBLEConnection">closeBLEConnection</a>: 断开与低功耗蓝牙设备的连接</li>
<li>
<a href="#plus.bluetooth.createBLEConnection">createBLEConnection</a>: 连接低功耗蓝牙设备</li>
<li>
<a href="#plus.bluetooth.getBLEDeviceCharacteristics">getBLEDeviceCharacteristics</a>: 获取蓝牙设备指定服务中所有特征值(characteristic)</li>
<li>
<a href="#plus.bluetooth.getBLEDeviceServices">getBLEDeviceServices</a>: 获取蓝牙设备的所有服务(service)</li>
<li>
<a href="#plus.bluetooth.notifyBLECharacteristicValueChange">notifyBLECharacteristicValueChange</a>: 启用低功耗蓝牙设备特征值变化时的notify功能,订阅特征值</li>
<li>
<a href="#plus.bluetooth.onBLECharacteristicValueChange">onBLECharacteristicValueChange</a>: 监听低功耗蓝牙设备的特征值变化事件</li>
<li>
<a href="#plus.bluetooth.onBLEConnectionStateChange">onBLEConnectionStateChange</a>: 监听低功耗蓝牙设备连接状态变化事件</li>
<li>
<a href="#plus.bluetooth.readBLECharacteristicValue">readBLECharacteristicValue</a>: 读取低功耗蓝牙设备指定特征值的二进制数据值</li>
<li>
<a href="#plus.bluetooth.writeBLECharacteristicValue">writeBLECharacteristicValue</a>: 向低功耗蓝牙设备指定特征值写入二进制数据</li>
</ul>
<h2>对象:</h2>
<ul>
<li>
<a href="#plus.bluetooth.BluetoothDeviceInfo">BluetoothDeviceInfo</a>: 蓝牙设备信息</li>
<li>
<a href="#plus.bluetooth.BluetoothService">BluetoothService</a>: 蓝牙设备服务信息</li>
<li>
<a href="#plus.bluetooth.Bluetoothcharacteristic">Bluetoothcharacteristic</a>: 蓝牙设备特征值</li>
<li>
<a href="#plus.bluetooth.BluetoothcharacteristicProperties">BluetoothcharacteristicProperties</a>: 蓝牙设备特征值支持的操作类型</li>
</ul>
<h2>回调方法:</h2>
<ul>
<li>
<a href="#plus.bluetooth.BluetoothSuccessCallback">BluetoothSuccessCallback</a>: 成功回调函数</li>
<li>
<a href="#plus.bluetooth.BluetoothFailCallback">BluetoothFailCallback</a>: 失败回调函数</li>
<li>
<a href="#plus.bluetooth.BluetoothCompleteCallback">BluetoothCompleteCallback</a>: 操作完成回调函数</li>
<li>
<a href="#plus.bluetooth.BluetoothAdapterStateChangeCallback">BluetoothAdapterStateChangeCallback</a>: 蓝牙适配器状态变化事件回调函数</li>
<li>
<a href="#plus.bluetooth.BluetoothDeviceFoundCallback">BluetoothDeviceFoundCallback</a>: 蓝牙适配器搜索到新设备事件回调函数</li>
<li>
<a href="#plus.bluetooth.BLEConnectionStateChangeCallback">BLEConnectionStateChangeCallback</a>: 低功耗蓝牙设备连接状态变化事件回调函数</li>
<li>
<a href="#plus.bluetooth.BLECharacteristicValueChangeCallback">BLECharacteristicValueChangeCallback</a>: 低功耗蓝牙设备的特征值变化事件回调函数</li>
</ul>
<h2>权限:</h2>
<p>5+功能模块(permissions)</p>
<pre class="prettyprint linenums">
{
// ...
"permissions":{
    // ...
    "Bluetooth": {
        "description": "Bluetooth"
    }
}
}
            </pre>
<h1><a name="plus.bluetooth.BluetoothDeviceInfo">BluetoothDeviceInfo</a></h1>
<p>蓝牙设备信息</p>
<pre class="prettyprint linenums">
interface BluetoothDeviceInfo {
    readonly attribute String name;
    readonly attribute String deviceId;
    readonly attribute String RSSI;
    readonly attribute ArrayBuffer advertisData;
    readonly attribute Array&lt;String&gt; advertisServiceUUIDs;
    readonly attribute String localName;
    readonly attribute JSON serviceData;
}            
                </pre>
<h2>属性:</h2>
<ul>
<li>name: <em>(<font class="type">String</font>
    类型
)</em>蓝牙设备名称<br><p>
    某些设备可能没有此字段值。
                        </p>
</li>
<li>deviceId: <em>(<font class="type">String</font>
    类型
)</em>蓝牙设备的id<br>
</li>
<li>RSSI: <em>(<font class="type">String</font>
    类型
)</em>蓝牙设备的信号强度<br>
</li>
<li>advertisData: <em>(<font class="type">ArrayBuffer</font>
    类型
)</em>蓝牙设备的广播数据段中的ManufacturerData数据段<br>
</li>
<li>advertisServiceUUIDs: <em>(<font class="type">Array</font>[
                <font class="type">String</font>
                ]
            
    类型
)</em>蓝牙设备的广播数据段中的ServiceUUIDs数据段<br>
</li>
<li>localName: <em>(<font class="type">String</font>
    类型
)</em>蓝牙设备的广播数据段中的LocalName数据段<br>
</li>
<li>serviceData: <em>(<font class="type">JSON</font>
    类型
)</em>蓝牙设备的广播数据段中的ServiceData数据段<br>
</li>
</ul>
<h1><a name="plus.bluetooth.BluetoothService">BluetoothService</a></h1>
<p>蓝牙设备服务信息</p>
<pre class="prettyprint linenums">
interface BluetoothService {
    readonly attribute String uuid;
    readonly attribute Boolean isPrimary;
}            
                </pre>
<h2>属性:</h2>
<ul>
<li>uuid: <em>(<font class="type">String</font>
    类型
)</em>蓝牙设备服务的uuid<br>
</li>
<li>isPrimary: <em>(<font class="type">Boolean</font>
    类型
)</em>是否为设备的主服务<br>
</li>
</ul>
<h1><a name="plus.bluetooth.Bluetoothcharacteristic">Bluetoothcharacteristic</a></h1>
<p>蓝牙设备特征值</p>
<pre class="prettyprint linenums">
interface Bluetoothcharacteristic {
    readonly attribute String uuid;
    readonly attribute BluetoothcharacteristicProperties properties;
}            
                </pre>
<h2>属性:</h2>
<ul>
<li>uuid: <em>(<font class="type">String</font>
    类型
)</em>蓝牙设备特征值的uuid<br>
</li>
<li>properties: <em>(<a href="#plus.bluetooth.BluetoothcharacteristicProperties">BluetoothcharacteristicProperties</a>
    类型
)</em>设备特征值支持的操作类型<br>
</li>
</ul>
<h1><a name="plus.bluetooth.BluetoothcharacteristicProperties">BluetoothcharacteristicProperties</a></h1>
<p>蓝牙设备特征值支持的操作类型</p>
<pre class="prettyprint linenums">
interface BluetoothcharacteristicProperties {
    readonly attribute Boolean read;
    readonly attribute Boolean write;
    readonly attribute Boolean notify;
    readonly attribute Boolean indicate;
}            
                </pre>
<h2>属性:</h2>
<ul>
<li>read: <em>(<font class="type">Boolean</font>
    类型
)</em>特征值是否支持read操作<br>
</li>
<li>write: <em>(<font class="type">Boolean</font>
    类型
)</em>特征值是否支持write操作<br>
</li>
<li>notify: <em>(<font class="type">Boolean</font>
    类型
)</em>特征值是否支持notify操作<br>
</li>
<li>indicate: <em>(<font class="type">Boolean</font>
    类型
)</em>特征值是否支持indicate操作<br>
</li>
</ul>
<h1><a name="plus.bluetooth.BluetoothSuccessCallback">BluetoothSuccessCallback</a></h1>
<p>成功回调函数</p>
<pre class="prettyprint linenums">
void onSuccess(JSON event){
}
                </pre>
<h2>说明:</h2>
<p class="des">
    不同接口触发的成功回调参数event包含的属性存在差异,具体参考对应的接口描述说明。
                </p>
<h2>参数:</h2>
<ul><li>event: 
        <em>(
            <font class="type">JSON</font>
            )
            必选 </em>回调参数<br>
    回调参数包含的属性由调用接口决定,具体参考对应的接口描述说明。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<h1><a name="plus.bluetooth.BluetoothFailCallback">BluetoothFailCallback</a></h1>
<p>失败回调函数</p>
<pre class="prettyprint linenums">
function void onFail(Exception error){
    // Handle error
    var code = error.code; // 错误编码
    var message = error.message; // 错误描述信息
}
                </pre>
<h2>参数:</h2>
<ul><li>error: 
        <em>(
            <font class="type">Exception</font>
            )
            必选 </em>回调参数,错误信息<br>
    可通过error.code(Number类型)获取错误编码;
    可通过error.message(String类型)获取错误描述信息。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<h1><a name="plus.bluetooth.BluetoothCompleteCallback">BluetoothCompleteCallback</a></h1>
<p>操作完成回调函数</p>
<pre class="prettyprint linenums">
function void onComplete(JSON event){
}
                </pre>
<h2>说明:</h2>
<p class="des">
    调用成功或失败都会触发此回调。
                </p>
<h2>参数:</h2>
<ul><li>event: 
        <em>(
            <font class="type">JSON</font>
            )
            可选 </em>回调参数<br>
    调用成功时回调参数与BluetoothSuccessCallback一致,调用失败时回调参数与BluetoothFailCallback一致。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<h1><a name="plus.bluetooth.BluetoothAdapterStateChangeCallback">BluetoothAdapterStateChangeCallback</a></h1>
<p>蓝牙适配器状态变化事件回调函数</p>
<pre class="prettyprint linenums">
function void onStateChange(JSON event){
    // event.available
    // event.discovering
}
                </pre>
<h2>说明:</h2>
<p class="des">
    蓝牙适配器状态发生变化时触发此回调。
                </p>
<h2>参数:</h2>
<ul><li>event: 
        <em>(
            <font class="type">JSON</font>
            )
            可选 </em>返回参数<br>
    回调函数参数event对象包括以下属性:
        available - Boolean,蓝牙适配器是否可用;
        discovering - Boolean,蓝牙适配器是否处于搜索状态。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<h1><a name="plus.bluetooth.BluetoothDeviceFoundCallback">BluetoothDeviceFoundCallback</a></h1>
<p>蓝牙适配器搜索到新设备事件回调函数</p>
<pre class="prettyprint linenums">
function void onDeviceFound(JSON event){
    // event.devices
}
                </pre>
<h2>说明:</h2>
<p class="des">
    搜索到蓝牙设备时触发此回调。
                </p>
<h2>参数:</h2>
<ul><li>event: 
        <em>(
            <font class="type">JSON</font>
            )
            可选 </em>返回参数<br>
    回调函数参数event对象包括以下属性:
        devices - Array&lt;BluetoothDeviceInfo&gt;,设备列表信息。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<h1><a name="plus.bluetooth.BLEConnectionStateChangeCallback">BLEConnectionStateChangeCallback</a></h1>
<p>低功耗蓝牙设备连接状态变化事件回调函数</p>
<pre class="prettyprint linenums">
function void onStateChange(JSON event){
    // event.deviceId
    // event.connected
}
                </pre>
<h2>说明:</h2>
<p class="des">
    蓝牙设备连接状态发生变化时触发此回调。
                </p>
<h2>参数:</h2>
<ul><li>event: 
        <em>(
            <font class="type">JSON</font>
            )
            可选 </em>返回参数<br>
    回调函数参数event对象包括以下属性:
        deviceId - String类型,蓝牙设备id;
        connected - Boolean类型,是否处于已连接状态。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<h1><a name="plus.bluetooth.BLECharacteristicValueChangeCallback">BLECharacteristicValueChangeCallback</a></h1>
<p>低功耗蓝牙设备的特征值变化事件回调函数</p>
<pre class="prettyprint linenums">
function void onValueChange(JSON event){
    // event.deviceId
    // event.serviceId
    // event.characteristicId
    // event.value
}
                </pre>
<h2>说明:</h2>
<p class="des">
    蓝牙设备对应的特征值发生变化时触发此回调。
                </p>
<h2>参数:</h2>
<ul><li>event: 
        <em>(
            <font class="type">JSON</font>
            )
            可选 </em>返回参数<br>
    回调函数参数event对象包括以下属性:
        deviceId - String类型,蓝牙设备id;
        serviceId - String类型,蓝牙服务的uuid;
        characteristicId - String类型,蓝牙特征值的uuid;
        value - ArrayBuffer类型,特征值的最新值。
                        </li></ul>
<h2>返回值:</h2>
<font class="type">void</font>
            : 无<br><br>
</div></body>
</html>