蓝牙API总结
BluetoothProfile(interface)
主要常量值:
表示目前GAP层的状态
STATE_CONNECTED
STATE_CONNECTING
STATE_DISCONNECTED
STATE_DISCONNECTING
公共方法(全是抽象的):
getConnectedDevices
返回值 list<BluetoothDevice>
获取已连接到的设备
getConnectionState(BluetoothDevice device)
返回值 获得某设备的连接状态
getDevicesMatchingConnectionStates(int[] states)
返回值 获得这一状态的设备列表
BluetoothAdapter.LeScanCallback(interface)
主要方法:
void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
回调函数,当LeScanCallback作为startLeScan函数参数时,宣告已经有一个函数被扫描到了
参数:
device 识别远程设备
rssi 如果蓝牙硬件能识别RSSI,则这个是它设别出的rssi,否则为0
scanRecord 远程设备广播的信息
BluetoothProfile.ServiceListener
主要方法:
onServiceConnected(int profile, BluetoothProfile proxy)
onServiceDisconnected(int profile)
当主机连接上服务端或者与其断开连接时的回调
第一个参数是识别码,第二个是profile 但是好像只能是音频模板,耳机模板,健康包模板之一
BluetoothAdapter public final
介绍:代表了本地蓝牙适配器。它能让你去执行一些底层蓝牙任务,例如启动发现设备,查询已配对设备,
用一个已知地址去建出一个设备模型,创建一个BluetoothServerSocket去监听来自其他设备的连接请求,或是
启动一个扫描动作。为了去得到一个蓝牙适配器,如果运行在Android4.3及其以上,可以使用getAdapter直接
获得。本质上来说,这也是你所有蓝牙行为的基本点。一旦你获得了本地适配器,你就能通过getBondedDevices()
得到一串已配对或者绑定的蓝牙设备,或者通过startDiscovery()去扫描蓝牙,或者创建getBondedDevices()
,通过listenUsingRfcommWithServiceRecord(String, UUID)去监听要来的连接请求,或者是去发起一段扫描。
这个类是线程安全的。
需要 BLUETOOTH 和 BLUETOOTH_ADMIN 权限
内嵌的类
BluetoothAdapter.LeScanCallback
回调,用来传递扫描结果
常量值
String
ACTION_CONNECTION_STATE_CHANGED
意图 把本地适配器连接状态广播给远程profile
String
ACTION_DISCOVERY_FINISHED
Broadcast Action: 已经完成了发现任务
String
ACTION_DISCOVERY_STARTED
Broadcast Action: 发现任务开始
String
ACTION_LOCAL_NAME_CHANGED
Broadcast Action: 本地适配器更换名字
String
ACTION_REQUEST_DISCOVERABLE
Activity Action: 请求可发现模式
String
ACTION_REQUEST_ENABLE
Activity Action: 请求打开蓝牙
String
ACTION_SCAN_MODE_CHANGED
Broadcast Action: 扫描模式已改变
String
ACTION_STATE_CHANGED
Broadcast Action: 本地蓝牙适配器的状态已改变
int
ERROR
错误型号
String
EXTRA_CONNECTION_STATE
ACTION_CONNECTION_STATE_CHANGED 附加物 代表连接状态
String
EXTRA_DISCOVERABLE_DURATION
ACTION_REQUEST_DISCOVERABLE 附加物 请求可发现几秒钟.
String
EXTRA_LOCAL_NAME
ACTION_LOCAL_NAME_CHANGED 适配器名字
String
EXTRA_PREVIOUS_CONNECTION_STATE
ACTION_CONNECTION_STATE_CHANGED 附加物 代表之前的状态
String
EXTRA_PREVIOUS_SCAN_MODE
ACTION_SCAN_MODE_CHANGED 附加物 代表之前的扫描模式
String
EXTRA_PREVIOUS_STATE
ACTION_STATE_CHANGED 附加物 之前的功率状态
String
EXTRA_SCAN_MODE
ACTION_SCAN_MODE_CHANGED 附加物 代表现在的扫描模式
String
EXTRA_STATE
ACTION_STATE_CHANGED 附加物 代表现在的功率状态
int
SCAN_MODE_CONNECTABLE
inquiry scan失能, page scan使能.
int
SCAN_MODE_CONNECTABLE_DISCOVERABLE
inquiry scan使能, page scan使能.
int
SCAN_MODE_NONE
inquiry scan失能, page scan失能.
int
STATE_CONNECTED
已连接状态
int
STATE_CONNECTING
连接状态
int
STATE_DISCONNECTED
断开连接状态
int
STATE_DISCONNECTING
正在断开连接状态
int
STATE_OFF
适配器已关
int
STATE_ON
适配器已打开
int
STATE_TURNING_ON
适配器正在打开
int
STATE_TURNING_OFF
适配器正在关闭
主要方法:
取消扫描:boolean
cancelDiscovery()
判断一个地址是否格式合法:static boolean
checkBluetoothAddress(String address)
取消使用proxy(健康包等代理): void closeProfileProxy(int profile, BluetoothProfile proxy)
断开连接,停止蓝牙系统,关闭蓝牙电源 boolean
disable()
同上 使能有关蓝牙的一切: boolean
enable()
返回本地蓝牙地址String
getAddress()
返回BluetoothLeAdvertiser去执行广播行为 BluetoothLeAdvertiser
getBluetoothLeAdvertiser()
返回BluetoothLeScannerBluetoothLeScanner去执行扫描操作
getBluetoothLeScanner()
返回已绑定的设备列表Set<BluetoothDevice>
getBondedDevices()
返回默认的蓝牙适配器static BluetoothAdapter
getDefaultAdapter()
返回广播最大字节数int
getLeMaximumAdvertisingDataLength()
本地蓝牙名字String
getName()
目前profile的连接状态:int
getProfileConnectionState(int profile)
返回一个与当前profile相关的proxy :boolean
getProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile)
通过地址去得到一个蓝牙设备:BluetoothDevice
getRemoteDevice(byte[] address)
获取本地扫描模式:int
getScanMode()
获取本地适配器模式(功率?):int
getState()
判断是否在进行发现boolean
isDiscovering()
判断蓝牙是否能使用:boolean
isEnabled()
ble是否支持的判断:
boolean
isLe2MPhySupported()
boolean
isLeCodedPhySupported()
某种广播是否支持的判断:
boolean
isLeExtendedAdvertisingSupported()
boolean
isLePeriodicAdvertisingSupported()
boolean
isMultipleAdvertisementSupported()
不明觉厉:
boolean
isOffloadedFilteringSupported()
boolean
isOffloadedScanBatchingSupported()
BluetoothServerSocket
listenUsingInsecureRfcommWithServiceRecord(String name, UUID uuid)
BluetoothServerSocket
listenUsingRfcommWithServiceRecord(String name, UUID uuid)
设置蓝牙名字:boolean
setName(String name)
开始发现:boolean
startDiscovery()
开启扫描:boolean
startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)
这个方法level21不能用,要用 startScan(List, ScanSettings, ScanCallback),并且在onLeScan里接受回调
停止扫描:void
stopLeScan(BluetoothAdapter.LeScanCallback callback)
这个方法level21不能用,要用stopScan(ScanCallback).
android蓝牙使能 安卓蓝牙api
转载-
android经典蓝牙 安卓蓝牙api
此小项目主要讲述了蓝牙的开发基础 比如 打开蓝牙 关闭蓝牙 扫描附近设备 获取附近设备信息 连接附近设备 等等 1.清单文件 AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.co
android经典蓝牙 Android 蓝牙开发 android 打开蓝牙功能 android 扫描蓝牙功能 BLUETOOTH_ADMIN -
android bluez蓝牙库 安卓蓝牙api
随着可穿戴设备的流行,蓝牙是必不可少的一门技术了。 1.简介 1.1.蓝牙有传统蓝牙(3.0以下)和低功耗蓝牙(ble,又称蓝牙4.0)之分。1.2.android手机必须系统版本4.3及以上才支持BLE API。低功耗蓝牙较传统蓝牙, 传输速度更快,覆盖范围更广,安全性更高,延迟更短,耗电极低等等优点。 1.3.传统蓝牙与低功耗蓝牙通信方式也有所不同,传统的一般通过socke
android bluez蓝牙库 android 蓝牙开发 android蓝牙智能穿戴 android蓝牙健康设备 传统蓝牙和低功耗蓝牙 -
android 普通lanya 安卓蓝牙api
android.bluetoothBluetoothAdapter表示本地蓝牙适配器(蓝牙无线装置)。BluetoothAdapter 是所有蓝牙交互的入口点。借助该类,您可以发现其他蓝牙设备、查询已绑定(已配对)设备的列表、使用已知的 MAC 地址实例化 BluetoothDevice,以及通过创建 BluetoothServerSocket 侦听来自其他
android 普通lanya Bluetooth API 蓝牙适配器 蓝牙API Android蓝牙 -
android 后台 蓝牙 安卓蓝牙程序
作者: 张奇 我将在这篇文章中介绍了的Android蓝牙程序。这个程序就是将实现把手机变做电脑PPT播放的遥控器:用音量加和音量减键来控制PPT页面的切换。遥控器服务器端首先,我们需要编写一个遥控器的服务器端(支持蓝牙的电脑)来接收手机端发出的信号。为了实现这个服务器端,我用到了一个叫做Bluecove(专门用来为蓝牙服务的!)的J
android 后台 蓝牙 Android蓝牙 蓝牙实例 bluetooth chat 蓝牙遥控器