[Android] Util method to remove files

Geoffrey Métais git at videolan.org
Tue Jan 6 18:10:38 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan  6 18:07:53 2015 +0100| [384b6097fc6a911f5e782b61485c91bf8e2e8015] | committer: Geoffrey Métais

Util method to remove files

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=384b6097fc6a911f5e782b61485c91bf8e2e8015
---

 vlc-android/src/org/videolan/vlc/util/Util.java |   24 +++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 8989519..7c77b2a 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -21,6 +21,7 @@
 package org.videolan.vlc.util;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -36,10 +37,13 @@ import org.videolan.vlc.VLCCallbackTask;
 import org.videolan.vlc.audio.AudioServiceController;
 
 import android.annotation.TargetApi;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.TypedArray;
+import android.net.Uri;
+import android.provider.MediaStore;
 import android.text.TextUtils.TruncateAt;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
@@ -248,4 +252,24 @@ public class Util {
         else
             editor.commit();
     }
+
+    public static boolean deleteFile (Context context, String path){
+        boolean deleted = false;
+        if (path.startsWith("file://"))
+            path = path.substring(5);
+        else
+            return deleted;
+        if (LibVlcUtil.isHoneycombOrLater()){
+            ContentResolver cr = context.getContentResolver();
+            String[] selectionArgs = { path };
+            deleted = cr.delete(MediaStore.Files.getContentUri("external"),
+                    MediaStore.MediaColumns.DATA + "=?", selectionArgs) > 0;
+        }
+        if (!deleted){
+            File file = new File(Uri.decode(path));
+            if (file.exists())
+                deleted = file.delete();
+        }
+        return deleted;
+    }
 }



More information about the Android mailing list