[Convert] descrithdevice. getType ()-a function that is often ignored. Do not use thdevice properties.
After Android 4.0 is released, more and more developers have received various development requirements for BLE Bluetooth.
In addition, many times we still need to be compatible with the previous version 3.0, which has brought us a lot of troubles in development. I also encountered such a problem and accidentally discovered the wonderful USE OF THE getType () function.
Public int getType () Added in API level 18
Get the Bluetooth device type of the remote device.
Returns the device type DEVICE_TYPE_CLASSIC, DEVICE_TYPE_LE DEVICE_TYPE_DUAL. DEVICE_TYPE_UNKNOWN if it's not available
Public static final int DEVICE_TYPE_CLASSIC Added in API level 18
Bluetooth device type, Classic-BR/EDR devices Constant Value: 1 (0x00000001)
Public static final int DEVICE_TYPE_DUAL Added in API level 18
Bluetooth device type, Dual Mode-BR/EDR/LE Constant Value: 3 (0x00000003)
Public static final int DEVICE_TYPE_LE Added in API level 18
Bluetooth device type, Low Energy-LE-only Constant Value: 2 (0x00000002)
Public static final int DEVICE_TYPE_UNKNOWN Added in API level 18
Bluetooth device type, Unknown Constant Value: 0 (0x00000000)
With this interface, you can easily define a function to distinguish the version of the searched bluetooth device. For example
| 12345678910111213141516 |
Public static String deviceTypeTyString (int paramInt) {switch (paramInt) {default: return "UNKNOWN"; case 1: return "CLASSIC"; case 3: return "CLASSIC and BLE "; case 2:} return "BLE only";} public static boolean isBLEDevice (descrithdevice device) {return (device. getType () = 2 );} |
For your reference only.
- Fixed Link: http://4past.net /? P = 72
- Reprinted, please note: Mr. X was published by Mr. X on December 31, September 02, 2015.