From 6d8fb3a13721550e4675cb831b25ca30455926dd Mon Sep 17 00:00:00 2001 From: gregorispielmann Date: Mon, 30 Mar 2020 09:46:41 -0300 Subject: [PATCH] correction of android 5 crash on RNBluetoothHeadsetDetectModule.java --- .../RNBluetoothHeadsetDetectModule.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/io/github/alexkorep/RNBluetoothHeadsetDetectModule.java b/android/src/main/java/io/github/alexkorep/RNBluetoothHeadsetDetectModule.java index 47e0234..898b4a8 100644 --- a/android/src/main/java/io/github/alexkorep/RNBluetoothHeadsetDetectModule.java +++ b/android/src/main/java/io/github/alexkorep/RNBluetoothHeadsetDetectModule.java @@ -88,15 +88,19 @@ public void onHostResume() { return; } final AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); - AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS); - for (AudioDeviceInfo device : devices) { - final int type = device.getType(); - if (type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP || type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO) { - // Device is found - final String deviceName = device.getProductName().toString(); - onChange(deviceName); - return; + try { + AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS); + for (AudioDeviceInfo device : devices) { + final int type = device.getType(); + if (type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP || type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO) { + // Device is found + final String deviceName = device.getProductName().toString(); + onChange(deviceName); + return; + } } + } catch(NoSuchMethodError e){ + //ignore in case of error } // No devices found onChange("");