[Android] File deletion: prevent crash

Geoffrey Métais git at videolan.org
Fri Mar 2 10:45:12 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar  2 10:19:41 2018 +0100| [bd9f84f7f2eab7d2ccbfef2a8ec608e02bad065d] | committer: Geoffrey Métais

File deletion: prevent crash

Also, normal delete method for pre-Lollipop devices

> https://code.videolan.org/videolan/vlc-android/commit/bd9f84f7f2eab7d2ccbfef2a8ec608e02bad065d
---

 vlc-android/src/org/videolan/vlc/util/FileUtils.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 10fcac1b5..fe7d50282 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -210,10 +210,13 @@ public class FileUtils {
         }
         return ret;
     }
-    public static boolean deleteFile (Uri uri){
-        if (uri.getPath().startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return deleteFile(uri.getPath());
+    public static boolean deleteFile (Uri uri) {
+        if (!AndroidUtil.isLolliPopOrLater || uri.getPath().startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return deleteFile(uri.getPath());
         final DocumentFile docFile = FileUtils.findFile(uri);
-        return docFile != null && docFile.delete();
+        if (docFile != null) try {
+            return docFile.delete();
+        } catch (Exception ignored) {}
+        return false;
     }
 
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)



More information about the Android mailing list