java - 将过滤器添加到蓝牙发现

标签 java android bluetooth

我只想在开始发现蓝牙设备时发现外围设备,我的应用不得发现/显示其他设备。这怎么可能?

这就是我搜索设备的方式

  IntentFilter filter = new IntentFilter("android.bluetooth.devicepicker.action.DEVICE_SELECTED");
  registerReceiver(mBtPickReceiver,filter);

  startActivity(new Intent("android.bluetooth.devicepicker.action.LAUNCH")
 .putExtra("android.bluetooth.devicepicker.action.EXTRA_NEED_AUTH",false));

最佳答案

要根据您的要求减少(过滤)搜索设备的数量,请检查所需蓝牙设备的类类型。知道类型后,您可以根据类类型过滤搜索到的蓝牙设备。例如:

BluetoothDevice btd = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

if(btd.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.bla_bla_bla)
{
   //do whatever you want with the filtered device
}

关于java - 将过滤器添加到蓝牙发现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12245135/

相关文章:

java - 如何从其类中的方法更改对象

Java PDFBox - 阅读和修改带有特殊字符(变音符号)的 pdf

Android:ListView 中的 HTML 链接 - 突出显示问题

android - 我可以在没有 Microsoft Health 应用的情况下连接到 Microsoft Band吗

java - Spring MVC - 将调度程序 url 模式设置为 "/"会导致 Controller 无法工作并出现 404 错误

java - 输入流或读取器。具有相同逻辑的方法

android - 使用 libGDX 或 Android SDK 的区别和优势?

Android矢量drawables vrs png

android - android中的蓝牙服务器和客户端

bluetooth - 是否可以在不配对的情况下通知 GATT 事件?