File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Android/src/com/davikingcode/DetectHeadset Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,23 @@ public class DetectHeadset {
8
8
static AudioManager myAudioManager ;
9
9
10
10
public DetectHeadset (Context context ) {
11
-
12
11
myAudioManager = (AudioManager ) context .getSystemService (Context .AUDIO_SERVICE );
13
12
}
14
13
15
14
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 ())
17
26
return true ;
18
- }else return false ;
19
- }
27
+ }
28
+ return false ;
29
+ }
20
30
}
You can’t perform that action at this time.
0 commit comments