Commit bd9f84f7 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

File deletion: prevent crash

Also, normal delete method for pre-Lollipop devices
parent fd411dbd
...@@ -210,10 +210,13 @@ public class FileUtils { ...@@ -210,10 +210,13 @@ public class FileUtils {
} }
return ret; return ret;
} }
public static boolean deleteFile (Uri uri){ public static boolean deleteFile (Uri uri) {
if (uri.getPath().startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return deleteFile(uri.getPath()); if (!AndroidUtil.isLolliPopOrLater || uri.getPath().startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return deleteFile(uri.getPath());
final DocumentFile docFile = FileUtils.findFile(uri); 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) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment