Android Get Bluetooth status

Source: Internet
Author: User

The author has recently been doing Bluetooth status to get things, summed up a set of Bluetooth status code, share the following:

Private Bluetoothadapter BA; Bluetooth Adapter BA = Bluetoothadapter.getdefaultadapter ();     Whether the Bluetooth adapter is present, that is, whether an error occurred if (BA = = null) {Isbluecon =-1; Error}else if (ba.isenabled ()) {int A2DP = ba.getprofileconnectionstate (BLUETOOTHPROFILE.A2DP);//can manipulate Bluetooth devices, such as the Bluetooth headset with play suspend function int headset = ba.getprofileconnectionstate (bluetoothprofile.headset);//bluetooth headset, support voice input output int health = BA. Getprofileconnectionstate (;//Bluetooth wearable device//check whether Bluetooth is connected to one of three devices to determine whether it is connected or open and not connected to the status int   flag =-1;   if (A2DP = = bluetoothprofile.state_connected) {flag = A2DP;   } else if (headset = = bluetoothprofile.state_connected) {flag = headset;   } else if (health = = bluetoothprofile.state_connected) {flag = health; }//Describes an if (flag = = 1) connection on three devices {Isbluecon = 1;//discontinued} else if (flag = =-1) {Networkinfo NetI      NFO = Cm.getnetworkinfo (Connectivitymanager.type_bluetooth);  if (NetInfo = = null) {Isbluecon = 1;//discontinued}    else {state BLT = netinfo.getstate ();         Isbluecon = Getdevstate (BLT); Inside the system, return the connection or not}}}else {Isbluecon = 2;//shut off}

public static enum state {        CONNECTED,        connecting,        disconnected,        disconnecting,        SUSPENDED,        UNKNOWN;        Private state () {        }    }

Android Get Bluetooth status

Related Article

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