Skip to content

Commit 07249e9

Browse files
authored
Merge pull request #6 from iamsidv/master
Detect bluetooth for API's above 26
2 parents 83e29ea + b59aa5d commit 07249e9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Android/src/com/davikingcode/DetectHeadset/DetectHeadset.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ public class DetectHeadset {
88
static AudioManager myAudioManager;
99

1010
public DetectHeadset(Context context) {
11-
1211
myAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
1312
}
1413

1514
public boolean _Detect() {
16-
if(myAudioManager.isWiredHeadsetOn() || myAudioManager.isBluetoothA2dpOn()){
15+
//Added validation for newer api's above 26.
16+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
17+
AudioDeviceInfo[] audioDeviceInfos = myAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
18+
for (int i=0;i<audioDeviceInfos.length; i++){
19+
if(audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO ||
20+
audioDeviceInfos[i].getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET)
21+
return true;
22+
}
23+
}else {
24+
//This should work as expected for the older api's
25+
if(myAudioManager.isWiredHeadsetOn() || myAudioManager.isBluetoothA2dpOn())
1726
return true;
18-
}else return false;
19-
}
27+
}
28+
return false;
29+
}
2030
}

0 commit comments

Comments
 (0)