With the release of the 4.0 Bluetooth protocol, a growing number of developers have received various development requirements for BLE Bluetooth.
And there are many times also need to be compatible with the previous 3.0 version, to the development of people to bring trouble, the author also encountered such problems, accidentally found GetType () This function of the magical.
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)
According to this interface, you can easily define a function to distinguish between the search for the Bluetooth device version. Such as
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 ( Span class= "crayon-h" > bluetoothdevice device ) { /span> return (device. GetType() = = 2); } |
It is for reference only.
- This article fixed link: http://4past.net/?p=72
- Reprint Please specify: Mr. X September 02, 2015 at Mr. X published
Go Bluetoothdevice.gettype ()-a function that is often ignored. It's good, don't do it.