From 02058a40b60fdf15ee0b42f0f0b6a9c3a90b99e7 Mon Sep 17 00:00:00 2001 From: Jaeseong Seo <07js23@gmail.com> Date: Fri, 10 Jan 2025 13:35:05 +0900 Subject: [PATCH] fix: support usb outputs --- .../java/com/pagecall/PagecallWebView.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/pagecall/src/main/java/com/pagecall/PagecallWebView.java b/pagecall/src/main/java/com/pagecall/PagecallWebView.java index 8c6dc71..8b4d675 100644 --- a/pagecall/src/main/java/com/pagecall/PagecallWebView.java +++ b/pagecall/src/main/java/com/pagecall/PagecallWebView.java @@ -226,39 +226,31 @@ private void updateCommunicationDevice() { this.nativeBridge.log("deviceChange", "Bluetooth output detected: " + bluetoothDevice.getProductName()); } return; + } else { + audioManager.stopBluetoothSco(); } - // 2. Headphone (Including earpieces) - AudioDeviceInfo headphoneDevice = null; + // 2. External devices (Headsets, earpieces, ...) + AudioDeviceInfo externalDevice = null; for (AudioDeviceInfo deviceInfo : devices) { - if (deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES || - deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET || - deviceInfo.getType() == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) { - headphoneDevice = deviceInfo; + if (deviceInfo.getType() != AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) { + externalDevice = deviceInfo; break; } } - if (headphoneDevice != null) { - audioManager.stopBluetoothSco(); + if (externalDevice != null) { audioManager.setSpeakerphoneOn(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - audioManager.setCommunicationDevice(headphoneDevice); + audioManager.setCommunicationDevice(externalDevice); } if (this.nativeBridge != null) { - this.nativeBridge.log("deviceChange", "Headphone output detected: " + headphoneDevice.getProductName()); + this.nativeBridge.log("deviceChange", "External output detected: " + externalDevice.getProductName()); } return; } // 3. Builtin - AudioDeviceInfo builtinDevice = null; - for (AudioDeviceInfo deviceInfo : devices) { - if (deviceInfo.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) { - builtinDevice = deviceInfo; - break; - } - } - audioManager.stopBluetoothSco(); + AudioDeviceInfo builtinDevice = devices.get(0); audioManager.setSpeakerphoneOn(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { audioManager.clearCommunicationDevice();