一.蓝牙开发要用到的api
1.BluetoothAdapter类。返回BluetoothAdapter实例,移动设备的本地蓝牙适配器。对蓝牙的基本操作如:启动设备发现,获取已匹配设备,通过mac蓝牙地址获取蓝牙设备等。
public static synchronized BluetoothAdapter getDefaultAdapter(); 获取实列
public boolean isEnabled(); 获取蓝牙开启状态
public boolean enable(); 开启蓝牙
public boolean disable(); 关闭蓝牙
public static boolean checkBluetoothAddress(String address); 检查MAC地址有效性
public String getAddress(); 获取MAC地址
public Set<BluetoothDevice> getBondedDevices(); 获取蓝牙绑定列表
public String getName(); 获取本地蓝牙适配器的蓝牙名称
public boolean setName(String name); 设置蓝牙名称
public int getScanMode();获取蓝牙扫描模式
startBluetoothDevicesDiscovery 开启设备可见
onBluetoothDeviceFound 查找蓝牙设备
getBluetoothDevices 获取蓝牙设备列表
2.BluetoothDevice类,远程连接的蓝牙设备
3.BluetoothServerSocket类,是一个监听蓝牙服务。使用accept方法阻塞,
4.BluetoothSocket类,是蓝牙套接口
二. 开发流程