Skip to content

Commit

Permalink
consider wired headphones #12
Browse files Browse the repository at this point in the history
  • Loading branch information
alamboley authored Apr 30, 2020
1 parent f484f95 commit 26312a2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Android/src/com/davikingcode/DetectHeadset/DetectHeadset.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ public DetectHeadset(Context context) {
myAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}

public boolean _Detect() {
public boolean _Detect()
{
//Added validation for newer api's above 26.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{
AudioDeviceInfo[] audioDeviceInfos = myAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
for (int i=0;i<audioDeviceInfos.length; i++){
if(audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO ||
audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET)
for (int i=0;i<audioDeviceInfos.length; i++)
{
if (audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO ||
audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET ||
audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES)
return true;
}
}else {
}
else
{
//This should work as expected for the older api's
if(myAudioManager.isWiredHeadsetOn() || myAudioManager.isBluetoothA2dpOn())
if (myAudioManager.isWiredHeadsetOn() || myAudioManager.isBluetoothA2dpOn())
return true;
}
return false;
Expand Down

0 comments on commit 26312a2

Please sign in to comment.