星空网 > 软件开发 > 操作系统

[转]BluetoothDevice.getType()

自动安卓发布了4.0版本的蓝牙协议之后,越来越多的开发者收到了各种针对于BLE蓝牙的开发需求。

而且有很多时候还需要兼容以前的3.0版本,给大家的开发带来了困扰,笔者也遇到了这样的问题,偶然间发现了getType()这个函数的妙用。

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)

跟据这个接口,你可以方便的定义一个函数用来分辨搜索到的蓝牙设备的版本。如

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

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( BluetoothDevice device ) {
    return (device.getType() == 2);
}



 

 仅供大家参考使用。
  • 本文固定链接: http://4past.net/?p=72
  • 转载请注明: X先生 2015年09月02日 于 X先生 发表




原标题:[转]BluetoothDevice.getType()

关键词:get

get
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流