Descrithdevice. getType ()-a function that is often ignored. Do not use thdevice properties.

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.