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)

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

 仅供大家参考使用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值