最近学习Bluetooth通讯的问题,看了几篇文章,再看API的时候更加觉得API才是王道,因此尝试自己翻译一下,借此学习理解。
英文原文:
class overview:
Represents the local device Bluetooth adapter. The BluetoothAdapter lets you perform fundamental Bluetooth tasks, such as initiate device discovery, query a list of bonded (paired) devices, instantiate a BluetoothDevice using a known MAC address, and create a BluetoothServerSocket to listen for connection requests from other devices, and start a scan for Bluetooth LE devices.
To get a BluetoothAdapter representing the local Bluetooth adapter, when running on JELLY_BEAN_MR1 and below, call the static getDefaultAdapter() method; when running on JELLY_BEAN_MR2 and higher, retrieve it through getSystemService(String) with BLUETOOTH_SERVICE. Fundamentally, this is your starting point for all Bluetooth actions. Once you have the local adapter, you can get a set of BluetoothDevice objects representing all paired devices with getBondedDevices(); start device discovery with startDiscovery(); or create a BluetoothServerSocket to listen for incoming connection requests with listenUsingRfcommWithServiceRecord(String, UUID); or start a scan for Bluetooth LE devices with startLeScan(LeScanCallback).Note: Most methods require the BLUETOOTH permission and some also require the BLUETOOTH_ADMIN permission.
中文翻译:
类概述:
BluetoothAdapter表示本地设备的蓝牙适配器。你可以利用BluetoothAdapter执行基本的蓝牙操作,比如发起蓝牙设备搜索,查询手机已连接(或配对)的设备列表,通过已知的MAC地址初始化一个蓝牙设备,以及生成一个BluetoothServerSocket类来监听其它设备的连接请求或者发起对其它蓝牙设备的搜索(Bluetooth LE 即 Bluetooth low energy)。
要获取到代表本机蓝牙适配器的BluetoothAdapter,在JELLY_BEAN_MR1(4.2)或者更低版本设备上,可以调用静态方法getDefaultAdapter();在JELLY_BEAN_MR2(4.3)及高版本上,调用getSystemService(String)并结合字符串常量BLUETOOTH_SERVICE。一般来说,操作蓝牙设备前都要先获取BluetoothAdapter。
一旦获取了本地的适配器,就可以通过
调用getBondedDevices()获取已配对设备集合;调用startDiscovery()开始蓝牙设备搜索;
调用 listenUsingRfcommWithServiceRecord(String, UUID)产生一个BluetoothServerSocket来监听连接请求;
调用startLeScan(LeScanCallback)扫描BLE设备。
注意:大部分的方法要求获得“BLUETOOTH”权限,一些也需要获得“BLUETOOTH_ADMIN”权限。