0
BT 장치 연결/연결 해제 용 브로드 캐스트 수신기를 등록하는 서비스를 시작하고 있습니다. 그것은 잘 작동하는 것 같습니다. 그러나 문제가 발생했습니다. BT 헤드셋이 이미 연결되어 있는지 감지해야 현재 상태를 알 수 있습니다. 나는 아래의 코드를 사용하지만, 그것 일하지 않는 것 같습니다 :서비스를 시작할 때 BT 헤드셋/헤드폰을 감지하는 방법
// ...
// get BluetoothAdapter
BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
// to tell if BT headset is connected
boolean isBtHeadsetOn = false;
// if device supports BT
if (ba != null) {
// get list of paired devices
Set<BluetoothDevice> devices = ba.getBondedDevices();
if (devices != null) {
// loop through devices
for (BluetoothDevice device : devices) {
// get device class
BluetoothClass bc = device.getBluetoothClass();
if (bc == null) continue;
int devClass = bc.getDeviceClass();
// check if device is handsfree, headphones or headset
if (devClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE || devClass == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES || devClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) {
// yes, it is
isBtHeadsetOn = true;
break;
}
}
}
}
// now I got my result in variable isBtHeadsetOn
// ...
내가 안드로이드 2.1 이상 코드를 개발하고이 서비스 #에서 onCreate에 위치를(). 도움 주셔서 감사합니다.
android 2.2 이상에서 해결 방법이 있습니다. 그렇지 않으면 운이 없어집니다. –