Index: webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java |
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java |
index a57e84f8ca0aa81ed8ba6596ec3831e16667044d..992d9188ba9881dd7492ea675957a1deb5c87421 100644 |
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java |
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java |
@@ -18,7 +18,9 @@ import android.content.Intent; |
import android.content.IntentFilter; |
import android.content.SharedPreferences; |
import android.content.pm.PackageManager; |
+import android.media.AudioDeviceInfo; |
import android.media.AudioManager; |
+import android.os.Build; |
import android.preference.PreferenceManager; |
import android.util.Log; |
@@ -437,7 +439,25 @@ public class AppRTCAudioManager { |
*/ |
@Deprecated |
private boolean hasWiredHeadset() { |
- return audioManager.isWiredHeadsetOn(); |
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
+ return audioManager.isWiredHeadsetOn(); |
+ } else { |
+ final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL); |
+ for (AudioDeviceInfo device : devices) { |
+ final int type = device.getType(); |
+ if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) { |
+ Log.d(TAG, "hasWiredHeadset: found wired headset"); |
+ return true; |
+ } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) { |
+ Log.d(TAG, "hasWiredHeadset: found USB audio device"); |
+ return true; |
+ } else if (type == AudioDeviceInfo.TYPE_USB_HEADSET) { |
+ Log.d(TAG, "hasWiredHeadset: found USB headset"); |
+ return true; |
+ } |
+ } |
+ return false; |
+ } |
} |
/** |