Code example for BluetoothHeadset

Methods: getConnectedDevices, getConnectionState

3
				if ( mBluetoothAdapter.isEnabled() == false || mBluetoothHeadset == null ) {
					returnNow = true;
					logMessage = "onHandleIntent/closeProfileProxy/During waiting for answering, BT may be disabled.";
				} 
				else { 
					btDevices = mBluetoothHeadset.getConnectedDevices();
					if ( btDevices.isEmpty() ) {
						returnNow = true;
						logMessage = "onHandleIntent/closeProfileProxy/No connected BT devices.";
					} 
					else if ( mBluetoothHeadset.getConnectionState(btDevices.get(0)) != BluetoothProfile.STATE_CONNECTED)  {
						returnNow = true;
						logMessage = "onHandleIntent/closeProfileProxy/No connected headset.";
					} 
				} 
				 
				mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
				 
				if( returnNow ) {
					Log.d(TAG, logMessage);
					return;