蓝牙
1.概念
蓝牙(Bluetooth) 是一种短距离无线通信技术 由于爱立信公司 在1994年创建的
蓝牙的设备有:蓝牙耳机,蓝牙鼠标,蓝牙适配器,蓝牙车载,蓝牙MP3,蓝牙网关
蓝牙的版本从1.0到4.2
2.wifi与蓝牙的区别
Wi-Fi和蓝牙的应用在某种程度上是互补的。Wi-Fi通常以接入点为中心,通过接入点与路由网络里形成非对称的客户机-服务器连接。而蓝牙通常是两个蓝牙设备间的对称连接。蓝牙适用于两个设备通过最简单的配置进行连接的简单应用,如耳机和遥控器的按钮,而Wi-Fi更适用于一些能够进行稍复杂的客户端设置和需要高速的应用中,尤其像通过存取节点接入网络。但是,蓝牙接入点确实存在,而且Wi-Fi的点对点连接虽然不像蓝牙一般容易,但也是可能的。Wi-Fi Direct是最近开发的、为Wi-Fi添加了类似蓝牙的点对点功能。
2.代码
android.bluetooth包下
蓝牙适配器对象 BluetoothAdapter
1.获取蓝牙适配器对象
BluetoothAdapter.getDefaultAdapter();
2.判断蓝牙是否可用
bluetoothAdapter.isEnabled()
3.设置蓝牙可用/不可用
bluetoothAdapter.enable()/bluetoothAdapter.disable()
4.进行扫描
bluetoothAdapter.startDiscovery()
5.判断是否正在扫描/取消扫描
bluetoothAdapter.isDiscovering()/bluetoothAdapter.cancelDiscovey()
6.得到已经配对好的设备
bluetoothAdapter.getBondedDevices()
蓝牙设置对象 BluetoothDevice
1.得到设备的mac地址
bluetoothDevice.getAddress()
2.得到设备的名称
bluetoothDevice.getName()
3.得到设备的状态
bluetoothDevice.getBondState()
3.1 已经配对的状态 BluetoothDevice.BOND_BONDED
3.2 正在进行配对的状态 BluetoothDevice. BOND_BONDING
3.3 未配对的状态 BluetoothDevice.BOND_NONE