public boolean isBlueToothHeadsetConnected() { boolean retval = true; try { retval = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) != android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; } catch (Exception exc) { // nothing to do } return retval; }
记得不要忘记在AndroidManifest.xml中添加蓝牙耳机权限。
<uses-permission android:name=”android.permission.BLUETOOTH” />
673