Android BluetoothDevice

一、BluetoothDevice介绍

BluetoothDevice是Android中用于表示蓝牙设备的类,它包含了蓝牙设备的名称、地址、类型等信息,并提供了一些方法用于连接、配对、获取设备信息等操作。在Android中,我们可以通过BluetoothAdapter来获取BluetoothDevice对象,然后进行相关操作。例如,我们可以使用BluetoothAdapter的getBoundedDevices()方法获取已经配对的蓝牙设备集合,然后使用BluetoothDevice的getName()方法获取设备名称,使用getAddress()方法获取设备地址等。此外,BluetoothDevice还提供了一些其他的方法,例如connectGatt()方法用于连接GATT服务器,createBond()方法用于配对设备等。

以下是一个获取已配对蓝牙设备名称和地址的例子:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
    for (BluetoothDevice device : pairedDevices) {
        String deviceName = device.getName();
        String deviceAddress = device.getAddress();
        Log.d(TAG, "deviceName: " + deviceName + ", deviceAddress: " + deviceAddress);
    }
}

二、BluetoothDevice相关接口

Attributable

Marker interface for a class which can have an AttributionSource assigned to it; these are typically Parcelable classes which need to be updated after crossing Binder transaction boundaries.

可以为其分配 AttributionSource 的类的标记接口;这些通常是 Parcelable 类,需要在跨越 Binder 事务边界后进行更新。

Attributable代码位于:

packages/modules/Bluetooth/framework/java/android/bluetooth/Attributable.java

Attributable的定义:

public interface Attributable {
    static @Nullable <T extends Attributable> T setAttributionSource(@Nullable T attributable, @NonNull AttributionSource attributionSource) {}
    static @Nullable <T extends Attributable> List<T> setAttributionSource(@Nullable List<T> attributableList, @NonNull AttributionSource attributionSource) {}
}

三、BluetoothDevice相关类

BluetoothDevice</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值