From 4ac31405e83206461bc306d982e8f45cb717ffcb Mon Sep 17 00:00:00 2001 From: Dusan Stevanovic Date: Fri, 14 Jun 2024 12:08:06 +0200 Subject: [PATCH] android: use explicit earpiece device --- .../waz/media/manager/router/AudioRouter.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/android/lib/src/main/java/com/waz/media/manager/router/AudioRouter.java b/android/lib/src/main/java/com/waz/media/manager/router/AudioRouter.java index 803a02262..11054e045 100644 --- a/android/lib/src/main/java/com/waz/media/manager/router/AudioRouter.java +++ b/android/lib/src/main/java/com/waz/media/manager/router/AudioRouter.java @@ -475,7 +475,22 @@ public int EnableEarpiece(){ DoLog("EnableEarpiece()"); if (hasApi31()) { - _audio_manager.clearCommunicationDevice(); + AudioDeviceInfo seldev = null; + List devices = _audio_manager.getAvailableCommunicationDevices(); + for (AudioDeviceInfo device : devices) { + if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) { + seldev = device; + break; + } + } + if (seldev == null) { + DoLog("EnableEarpiece(): no earpiece"); + return -1; + } + else { + DoLog("EnableEarpiece: setting communication device"); + _audio_manager.setCommunicationDevice(seldev); + } } else { if(!hasEarpiece())