如何在尝试查找BLE设备时使用LeDeviceListAdapter?

时间:2013-09-24 10:02:58

标签: android bluetooth-lowenergy

我正在使用Android中的应用程序,并且我遵循Android developers page

中的Codesuggestion

当我输入代码时:

private LeDeviceListAdapter mLeDeviceListAdapter;

它有错误消息:

  

LeDeviceListAdapter无法解析为类型

我该怎么做才能解决这个错误?

2 个答案:

答案 0 :(得分:8)

代码实际上只是Android SDK中BTLE示例项目的摘录。您应该一起阅读带有示例项目的文章。

示例项目的路径是/ sdk / samples / android-18 / legacy / BluetoothLeGatt

如果您只对LeDeviceListAdapter感兴趣,请参阅pastebin

中的代码

另外,我建议您阅读AdapterView(ListView的父级)和适配器的工作原理。与实际的BLE工作无关,但如果您不了解正在发生的事情,您将会理解示例代码。

答案 1 :(得分:5)

LeDeviceListAdapter类未内置于Android API中;你必须自己创造它。我在这个链接上找到了这个类 - 这是Android教程打算让你使用的类:

https://android.googlesource.com/platform/development/+/7167a054a8027f75025c865322fa84791a9b3bd1/samples/BluetoothLeGatt/src/com/example/bluetooth/le/DeviceScanActivity.java

只需在页面中搜索“LeDeviceListAdapter”。