From 3618f1e211c80bb1a17ad4e1393b2ca582cc638c Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Sat, 4 Feb 2023 11:28:12 +0100 Subject: [PATCH] Catch possible exception in getDownloadsUri --- .../java/com/emanuelef/remote_capture/Utils.java | 13 ++++++++++--- app/src/main/res/values/strings.xml | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/Utils.java b/app/src/main/java/com/emanuelef/remote_capture/Utils.java index 8923156f..7e5d5c10 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/Utils.java +++ b/app/src/main/java/com/emanuelef/remote_capture/Utils.java @@ -803,9 +803,16 @@ public class Utils { } } catch (Exception ignored) {} - Uri newUri = context.getContentResolver().insert(externalUri, values); - Log.d(TAG, "getDownloadsUri: new file " + newUri); - return newUri; + try { + Uri newUri = context.getContentResolver().insert(externalUri, values); + Log.d(TAG, "getDownloadsUri: new file " + newUri); + return newUri; + } catch (Exception e) { + // On some devices, it may trigger "IllegalArgumentException: Volume external_primary not found" + Log.e(TAG, "getDownloadsUri failed:" + e.getMessage()); + Utils.showToastLong(context, R.string.write_ext_storage_failed); + return(null); + } } public static boolean isRootAvailable() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 27bb7dbb..0f7af2f5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -453,4 +453,5 @@ Dump packets in the pcapng dump format, which allows embedding TLS decryption secrets Sort by Total bytes + Write to external storage failed. Check the app log for details