gpt4 book ai didi

android - 无需扫描即可连接其他蓝牙 LE 设备?

转载 作者:行者123 更新时间:2023-11-29 15:18:04 24 4
gpt4 key购买 nike

是否可以在不扫描的情况下与其他蓝牙 LE 设备连接。

当蓝牙打开时我正在开发应用程序,然后当我进入任何市场时自动收到通知,表明 Beacon 设备(基本上是蓝牙 LE)在您的范围内。没有我的扫描蓝牙乐。我的蓝牙刚刚打开。没有扫描。

因为我们的要求是蓝牙不只是扫描,当新的 BLE 在范围内时显示警报或任何通知。

我实现了一些扫描方法

startScan(){} 
stopScan(){}
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {}

但我不希望我直接想要获取连接消息。

请以代码 fragment 的形式帮助我,并提供一些解释
谢谢

最佳答案

您可以使用蓝牙适配器。

BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(mac);
device.connectGatt(mContext, false, mGattCallback);
// TODO your code

如果蓝牙设备不在身边,在 BluetoothGattCallback 的 onConnectionStateChange 中会报告 BluetoothGatt.STATE_DISCONNECTED。

BluetoothDevice 的创建者具有包范围。但是BluetoothAdapter的getRemoteDevice的源码是:

public BluetoothDevice getRemoteDevice(String address) {
return new BluetoothDevice(address);
}

关于android - 无需扫描即可连接其他蓝牙 LE 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22168659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com