Android蓝牙4.0API内容-接口-BluetoothProfile

本文详细介绍了用于蓝牙配置文件的PublicAPIs,包括如何通过getProfileProxy方法获取ProfileProxy对象来与不同蓝牙配置文件(如A2DP、GATT等)进行交互。此外还讲解了BluetoothProfile.ServiceListener接口的作用及其实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Public APIs for the Bluetooth Profiles配置文件. 

Clients should call getProfileProxy(Context, BluetoothProfile.ServiceListener, int), to get the Profile Proxy代理. Each public profile implements this interface.

关于getProfileProxy方法

Get the profile proxy object associated交互 with the profile.

Profile can be one of HEALTHHEADSETA2DPGATT, or GATT_SERVER. Clients must implement BluetoothProfile.ServiceListener to get notified 通知of the connection status and to get the proxy object.

方法中的参数

context  Context: Context of the application

listener  BluetoothProfile.ServiceListener: The service Listener for connection callbacks.

profile    int: The Bluetooth profile; either HEALTHHEADSETA2DPGATT or GATT_SERVER.

返回值类型为boolean

BluetoothProfile.ServiceListener接口描述

An interface for notifying BluetoothProfile IPC clients when they have been connected or disconnected to the service.

通知链接状态

其中的两个方法:1.public abstract vois onServiceConected(int profile,BluetoothProfile proxy)

profile int: - One of HEALTHHEADSET or A2DP

proxy BluetoothProfile: - One of BluetoothHealthBluetoothHeadset or BluetoothA2dp

2.public abstract void onServiceDIsConected(int profile)

profile int: - One of HEALTHHEADSET or A2DP

常量:

String EXTRA_PREVIOUS_STATE

String EXTRA_STATE

int A2DP 蓝牙音频协议

int GATT

int GATT_SERVER

int HEADSET 协议类型

int HEALTH 协议类型

int SAP

int STATE_CONNECTED 链接状态

int STATE_CONNECTING 连接中

int STATE_DISCONNECTED

int STATE_DISCONNECTING

公有的方法

abstract List<BluetoothDevice> getConnectedDevices()

Get connected devices for this specific profile.
获取设备列表
abstract int  getConnectionState( BluetoothDevice device)

  Get the current connection state of the profile

Requires BLUETOOTH permission.

abstratct   List<BluetoothDevicegetDevicesMatchingConnectionStates(int[] states)

Get a list of devices that match any of the given connection states.获取目标链接状态的设备列表


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值