owncloud-android-external
authorPeter Henn <Peter.Henn@web.de>
Tue, 7 Jul 2015 22:57:49 +0000 (22:57 +0000)
committerPeter Henn <Peter.Henn@web.de>
Tue, 7 Jul 2015 22:57:49 +0000 (22:57 +0000)
Generate ocl android app with external storage patches,
which was original found here:
https://github.com/owncloud/android/issues/10
and here:
https://github.com/de-live-gdev/owncloud-android-external
Just use the getAppContext() API from class MainApp to
get the value of mContext.

src/com/owncloud/android/utils/FileStorageUtils.java

index 892a1ca..d0f457e 100644 (file)
@@ -39,12 +39,25 @@ import android.os.StatFs;
  * @author David A. Velasco
  */
 public class FileStorageUtils {
-    //private static final String LOG_TAG = "FileStorageUtils";
+    //private static final String TAG = FileStorageUtils.class.getSimpleName();
+
+    @SuppressLint("NewApi")
+    private static final File getBaseStorePath() {
+        File baseStoragePath = Environment.getExternalStorageDirectory();
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
+            File[] dirs = MainApp.getAppContext().getExternalFilesDirs(null);
+            if (dirs.length > 1) {
+                baseStoragePath = dirs[1];
+            }
+        }
+        return baseStoragePath;
+    }
 
     public static final String getSavePath(String accountName) {
-        File sdCard = Environment.getExternalStorageDirectory();
-        return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@");
+        //File sdCard = Environment.getExternalStorageDirectory();
+        //return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@");
         // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
+        return getBaseStorePath().getAbsolutePath()  + "/" + Uri.encode(accountName, "@");
     }
 
     public static final String getDefaultSavePathFor(String accountName, OCFile file) {
@@ -52,14 +65,16 @@ public class FileStorageUtils {
     }
 
     public static final String getTemporalPath(String accountName) {
-        File sdCard = Environment.getExternalStorageDirectory();
-        return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/tmp/" + Uri.encode(accountName, "@");
+        //File sdCard = Environment.getExternalStorageDirectory();
+        //return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/tmp/" + Uri.encode(accountName, "@");
             // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
+        return getBaseStorePath().getAbsolutePath() + "/tmp/" + Uri.encode(accountName, "@");
     }
 
     @SuppressLint("NewApi")
     public static final long getUsableSpace(String accountName) {
-        File savePath = Environment.getExternalStorageDirectory();
+        //File savePath = Environment.getExternalStorageDirectory();
+        File savePath = getBaseStorePath();
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
             return savePath.getUsableSpace();