[轉]BluetoothDevice.getType()-一個常常被忽略了的函數。好用的不要不要的

來源:互聯網
上載者:User

標籤:

自動安卓發布了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)

跟據這個介面,你可以方便的定義一個函數用來分辨搜尋到的藍牙裝置的版本。如

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

 

 僅供大家參考使用。
  • 本文固定連結: http://4past.net/?p=72
  • 轉載請註明: X先生 2015年09月02日 於 X先生 發表

[轉]BluetoothDevice.getType()-一個常常被忽略了的函數。好用的不要不要的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.