如何获取蓝牙低功耗设备的别名?

问题描述 投票:0回答:1

如此处图片所示:

BLE Scanner getting Alias if exists

我正在尝试在我的应用程序上做同样的事情。我能够获取设备名称和几乎所有我需要的信息,但我无法获取别名,通过 android 应用程序 BLE 扫描仪知道,首先:它存在,其次:可以获取它.

我确实尝试过使用该方法:

try {

            Method m = device.getNative().getClass().getMethod("getAlias");
            Object res = null;
            if (m != null ) {
                res = m.invoke(device.getNative());
            }
            if(res != null)
                Alias = res.toString();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        if(name == null)
            name = device.getName_debug();

device.getNative() 访问BluetoothDevice 的较低级别实例。 但它返回的是设备名称而不是别名。

注意:也许“别名”不是描述我试图访问的变量的正确词。

如果有人可以帮助我,我将不胜感激。

android bluetooth-lowenergy
1个回答
0
投票

也许不是答案,但我想为其他使用 ESP32 遇到此问题的人留下痕迹。我发现调用 SDK 函数将设备名称写入闪存将始终是“别名”,即使我在运行时的设备名称不同。不确定这在堆栈中如何工作。

© www.soinside.com 2019 - 2024. All rights reserved.