如何检查配对的蓝牙设备是打印机还是扫描仪(Android) [英] How to Check if an Paired Bluetooth device is a Printer or a Scanner (Android)
问题描述
我希望可以帮助我, 我正在开发一个Android应用,该应用需要连接蓝牙设备(例如扫描仪和打印机),目前我可以列出所有配对的设备,但是我想知道配对的设备是否是打印机,扫描仪,移动设备等.
I hope can help me, I am developing an Android App, that require to connect with Bluetooth devices, like Scanner and Printer, currently I can list all Paired devices, but i want to know if the paired device is a Printer, Scanner, Mobile, etc.
有什么方法可以知道配对的蓝牙设备?
There is some way to know the kind of bluetooth device paired?
推荐答案
简而言之,
是的,可以.你 可以通过使用设备的 UUID 来实现.如果您知道设备的UUID,则可以从报告的UUID中将它们进行匹配,并知道哪个配对的设备是什么.
Yes you can. You can do this by using the UUID of the device. If you know the UUID of a device you can match them up from the reported UUID and know which paired device is what.
类似这样的东西:
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);
现在,只需将检索到的UUID与已知的UUID(在线或盒装)进行比较即可.
Now simply compare the retrieved UUID to the devices known UUID( online or on the box).
如果它们是匹配项,您就知道它是什么设备.
If they are a match you know what device it is.
注意:最常见的UUID(扫描仪,打印机,鼠标)具有通用UUID 0001101-0000-1000-8000-00805F9B34FB
Note: most common UUID (scanners, printers, Mice) have the generic UUID 0001101-0000-1000-8000-00805F9B34FB
了解 getUUID()方法,可设置的方法, Java.util.UUID.
Read about the getUUID() method, paracable method , Method java class and finally Java.util.UUID.
这篇关于如何检查配对的蓝牙设备是打印机还是扫描仪(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!