[Android] Catch NPE thrown by framework in getExternalCacheDir()

Geoffrey Métais git at videolan.org
Thu Apr 9 16:09:01 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr  9 16:05:58 2015 +0200| [4aae9ab4951f403bebf1a31619e06e65bb38321e] | committer: Geoffrey Métais

Catch NPE thrown by framework in getExternalCacheDir()

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

 vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index ef6bc3b..88c45da 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -119,10 +119,14 @@ public class AudioUtil {
 
     @SuppressLint("NewApi")
     public static void prepareCacheFolder(Context context) {
-        if (LibVlcUtil.isFroyoOrLater() && AndroidDevices.hasExternalStorage() && context.getExternalCacheDir() != null)
-            CACHE_DIR = context.getExternalCacheDir().getPath();
-        else
+        try {
+            if (LibVlcUtil.isFroyoOrLater() && AndroidDevices.hasExternalStorage() && context.getExternalCacheDir() != null)
+                CACHE_DIR = context.getExternalCacheDir().getPath();
+            else
+                CACHE_DIR = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
+        } catch (Exception e) { // catch NPE thrown by getExternalCacheDir()
             CACHE_DIR = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
+        }
         ART_DIR = CACHE_DIR + "/art/";
         COVER_DIR = CACHE_DIR + "/covers/";
         PLAYLIST_DIR = CACHE_DIR + "/playlists/";



More information about the Android mailing list