[Android] Prevent crash on file deletion

Geoffrey Métais git at videolan.org
Thu Feb 2 11:35:09 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb  2 11:34:40 2017 +0100| [b6fb54d94a6c549db313d74cace5570e58308101] | committer: Geoffrey Métais

Prevent crash on file deletion

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

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

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 1686430..12a43fb 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -25,7 +25,6 @@ package org.videolan.vlc.util;
 
 import android.annotation.TargetApi;
 import android.content.ContentResolver;
-import android.content.Intent;
 import android.content.res.AssetManager;
 import android.database.Cursor;
 import android.net.Uri;
@@ -205,9 +204,10 @@ public class FileUtils {
         //Delete from Android Medialib, for consistency with device MTP storing and other apps listing content:// media
         if (AndroidUtil.isHoneycombOrLater()){
             ContentResolver cr = VLCApplication.getAppContext().getContentResolver();
-            String[] selectionArgs = { path };
-            deleted = cr.delete(MediaStore.Files.getContentUri("external"),
-                    MediaStore.Files.FileColumns.DATA + "=?", selectionArgs) > 0;
+            try {
+                deleted = cr.delete(MediaStore.Files.getContentUri("external"),
+                        MediaStore.Files.FileColumns.DATA + "=?", new String[]{path}) > 0;
+            } catch (IllegalArgumentException ignored) {} // Can happen on some devices...
         }
         File file = new File(path);
         if (file.exists())



More information about the Android mailing list