Created
December 11, 2012 07:20
-
-
Save Bencodes/4256543 to your computer and use it in GitHub Desktop.
Revisions
-
Ben Lee revised this gist
Dec 11, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -47,10 +47,10 @@ public static File getStorageDirectory (final Context context, final Storage sto switch (storage) { case EXTERNAL: case EXTERNAL_CACHE: { // Check If External Even Exists if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { directory = (storage == Storage.EXTERNAL) ? Environment.getExternalStorageDirectory() : context.getExternalCacheDir(); break; } -
Ben Lee revised this gist
Dec 11, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public static enum Storage { * @param subDirectory A sub directory path just in case you want to get a sub directory * @return */ public static File getStorageDirectory (final Context context, final Storage storage, final String subDirectory) { final File directory; switch (storage) { -
Ben Lee created this gist
Dec 11, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ public final class StorageUtil { public static enum Storage { /** * /data/data/com.my.package/data/files/ */ INTERNAL, /** * (Varies on manufacturer) * /mnt/sdcard/ * /sdcard/ * <p/> * etc... */ EXTERNAL, /** * /data/data/com.my.package/data/cache/ */ INTERNAL_CACHE, /** * (Varies on manufacturer) * /mnt/sdcard/Android/data/com.my.package/cache/ * /sdcard/Android/data/com.my.package/cache/ * <p/> * etc... */ EXTERNAL_CACHE; } /** * A simple all-in-one method for getting File paths in Android. * If you request EXTERNAL/EXTERNAL_CACHE and there is no mounted external * storage, it will automatically default to internal. * * @param context Context so that it can request the appropriate File path. * @param storage Enum value for the preferred location (External/Internal) * @param subDirectory A sub directory path just in case you want to get a sub directory * @return */ public static File getStorageDirectory (final Context context, final Storage storage, String subDirectory) { final File directory; switch (storage) { case EXTERNAL: case EXTERNAL_CACHE: { // Check If External Even Exists if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { directory = (storage == Storage.EXTERNAL) ? context.getExternalFilesDir(null) : context.getExternalCacheDir(); break; } } case INTERNAL: { directory = context.getFilesDir(); break; } case INTERNAL_CACHE: { directory = context.getCacheDir(); break; } default: { return null; } } return new File(directory, subDirectory); } public static File getStorageDirectory (final Context context, final Storage storage) { return getStorageDirectory(context, storage, null); } }