[Android] File deletion: prevent crash
Geoffrey Métais
git at videolan.org
Wed Mar 7 15:22:39 CET 2018
vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 2 10:19:41 2018 +0100| [dfa3bf10f86152b3c2ac52750c69814492c8ff4b] | committer: Geoffrey Métais
File deletion: prevent crash
Also, normal delete method for pre-Lollipop devices
(cherry picked from commit bd9f84f7f2eab7d2ccbfef2a8ec608e02bad065d)
> https://code.videolan.org/videolan/vlc-android/commit/dfa3bf10f86152b3c2ac52750c69814492c8ff4b
---
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