FM: add headset detection logic using AudioManager API
Check if current audioManager outputDevice list contains
WIRED_HEADSET or WIRED_HEADPHONES device.
CRs-Fixed: 2438531
Change-Id: I7321d9eb24e84481cdebf6312b8e3ea1382b4950
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 884f255..ce39f38 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -288,7 +288,16 @@
getA2dpStatusAtStart();
mGainFocusReq = requestAudioFocus();
-
+ AudioManager mAudioManager =
+ (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ AudioDeviceInfo[] deviceList = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
+ for (int index = 0; index < deviceList.length; index++) {
+ if ((deviceList[index].getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET ) ||
+ (deviceList[index].getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES )){
+ mHeadsetPlugged = true;
+ break;
+ }
+ }
}
@Override