소스 검색

Fallback to normal cache dir if there is no external

Sebastián Katzer 8 년 전
부모
커밋
16fa62f4da
1개의 변경된 파일14개의 추가작업 그리고 9개의 파일을 삭제
  1. 14 9
      src/android/notification/util/AssetUtil.java

+ 14 - 9
src/android/notification/util/AssetUtil.java

@@ -129,10 +129,8 @@ public final class AssetUtil {
         String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
         File file       = getTmpFile(fileName);
 
-        if (file == null) {
-            Log.e("Asset", "Missing external cache dir");
+        if (file == null)
             return Uri.EMPTY;
-        }
 
         try {
             AssetManager assets = context.getAssets();
@@ -189,10 +187,8 @@ public final class AssetUtil {
     private Uri getUriFromRemote(String path) {
         File file = getTmpFile();
 
-        if (file == null) {
-            Log.e("Asset", "Missing external cache dir");
+        if (file == null)
             return Uri.EMPTY;
-        }
 
         try {
             URL url = new URL(path);
@@ -340,7 +336,11 @@ public final class AssetUtil {
         File dir = context.getExternalCacheDir();
 
         if (dir == null) {
-            Log.e("Asset", "Missing external cache dir");
+            dir = context.getCacheDir();
+        }
+
+        if (dir == null) {
+            Log.e("Asset", "Missing cache dir");
             return null;
         }
 
@@ -360,8 +360,13 @@ public final class AssetUtil {
      * @return content://...
      */
     private Uri getUriFromFile(File file) {
-        String authority = context.getPackageName() + ".provider";
-        return AssetProvider.getUriForFile(context, authority, file);
+        try {
+            String authority = context.getPackageName() + ".provider";
+            return AssetProvider.getUriForFile(context, authority, file);
+        } catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            return Uri.EMPTY;
+        }
     }
 
     /**