gpt4 book ai didi

java - 如何检查配对的蓝牙设备是打印机还是扫描仪 (Android)

转载 作者:太空狗 更新时间:2023-10-29 15:52:50 26 4
gpt4 key购买 nike

希望能帮到我,我正在开发一个 Android 应用程序,需要连接蓝牙设备,如扫描仪和打印机,目前我可以列出所有配对的设备,但我想知道配对的设备是打印机、扫描仪、手机等。

有什么方法可以知道配对的蓝牙设备的种类?

最佳答案

接受的答案过于笼统,因为 UUID 0001101-0000-1000-8000-00805F9B34FB 断言设备具有串行端口功能,而许多非打印机设备具有这种 UUID。

你应该评估完整的 CoD,在这个 link您可以为需要识别的服务提取精确的位掩码,对于打印机来说是:

0b000001000000011010000000

用这个你可以在完整的设备 CoD 上做一个掩码:

private static boolean isAPrinter(BluetoothDevice device){
int printerMask = 0b000001000000011010000000;
int fullCod = device.getBluetoothClass().hashCode();
Log.d(TAG, "FULL COD: " + fullCod);
Log.d(TAG, "MASK RESULT " + (fullCod & printerMask));
return (fullCod & printerMask) == printerMask;
}

关于java - 如何检查配对的蓝牙设备是打印机还是扫描仪 (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27302060/

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