1 import android
2 import time
3
4 droid = android.Android()
5 droid.toggleBluetoothState(True)
6 cnRst = droid.bluetoothConnect(
7 "00001101-0000-1000-8000-00805F9B34FB")
8
9 print(cnRst)
10
11 if cnRst.result:
12 while True:
13 message = droid.bluetoothReadLine().result
14 print(message)
15
16 droid.exit()
droid.bluetoothConnect("00001101-0000-1000-8000-00805F9B34FB")
做为参数的字符串是用于bluetoothConnect的uuid,它是蓝牙串口服务ID,因为SL4A没有提供类似createRfcommSocketToServiceRecord的API,所以我们需要使用该uuid来打开蓝牙串口服务
当bluetoothConnect执行完成,cnRst会得到成功的返回值,这时候就可以使用bluetoothReadLine等函数读写该串口了
网友评论