-
Notifications
You must be signed in to change notification settings - Fork 24
SDCardHelper
This class intended to help to access to external flash drive which was represented by removable SD(TF) card. You can get the app cache folder, know if drive is accessible to read or write, etc.
public static long getAvailableSpace()
Returns the free space (in bytes) available on External Storage Drive (SD card) or -1 if storage is not available (UNMOUNTED, etc)
public static File getSDRootPath()
Returns External Storage Drive (SD card) root() path
public static File getFileForPreviewImageCaching(final URL url)
Returns a File to store a preview of an image. File name is based on MD5(url) located on External Storage Drive in cache directory. Creates path (mkdirs) if necessary. Returns null if given url is null.
public static File getFileForPreviewImageCaching(final String sURL)
Returns a file to store a preview of an image to. File name based on MD5(url) located on External Storage Drive in cache directory. Creates path (mkdirs) if necessary. Returns null if given url is null.
public static File getFileForImageCaching(final URL url)
Returns a File to store downloading image to. The file name is based on MD5(url) and its path leads to External Storage Drive cache directory. Creates path (mkdirs) if necessary.
public static File getFileForImageCaching(final String sURL)
Returns a File to store downloading image to. The file name is based on MD5(url) and its path leads to External Storage Drive cache directory. Creates path (mkdirs) if necessary.
public static boolean isImageCached(final URL url)
Checks if given image was already cached/stored. File name is based on MD5(url) and its path leads to External Storage Drive cache directory. Creates path (mkdirs) if necessary.
public static boolean isImageCached(final String sURL)
Checks if given image was already cached/stored. File name is based on MD5(url) and its path leads to External Storage Drive cache directory. Returns true if file with such name exists of false otherwise.
public static File getTempFile(String fileExtension)
Generates a temporary file ensuring its path exists (mkdirs). Its path leads to an External Storage Drive if drive is available or using context.getCacheDir() otherwise. The fileExtension could be omitted (like "txt" instead of ".txt") and in such case dot will be added.
public static File getTempFile()
Generates a temporary file ensuring its path exists (mkdirs). Its path leads to an External Storage Drive if drive is available or from context.getCacheDir() method otherwise.
public static boolean saveImage(final String sURL, final byte[] img)
Stores (caches) the image on SD card using URL to generate an unique filename based on MD5(URL). Uses getFileForImageCaching(url), returns true if result is OK.
private static File getFile(final String sURL)
This method returns prepared a File which name is based on MD5 of it's URL.
private static File getPreviewFile(final String sURL)
Generates a File to store image preview to. Basically it adds the "/preview" string to the given url and then calls getFileForImageCaching(resulting URL). Returns null if sURL is null.
public static boolean isExternalStorageAvailable()
Checks and returns true if SD card (External Drive) is available.
public static boolean isExternalStorageWritePermissionGranted()
Checks permissions and returns true if SD card (External Drive) is available to write to. Applicable to API 23 and higher.
public static boolean isExternalStorageReadPermissionGranted()
Checks permissions and returns true if SD card (External Drive) is available to read from. Applicable to API 23 and higher.
public static boolean isReadable()
public static boolean isExternalStorageReadable()
Both methods do the same, check and return true if SD card available to read from.
public static boolean isWriteable()
public static boolean isExternalStorageWritable()
Both methods do the same, check and return true if SD card available to write to.
public static boolean clearImagesCache()
Method used to clear/empty the cache by deleting stored/cached images (basically all the files) in getCacheDir() directory. Does not delete subdirectories and its files. Returns true if all went OK.
public static boolean clearCacheFilesOnly()
Method used to clear/empty the cache by deleting stored/cached files (images) in getCacheDir() directory. Does not delete subdirectories and its files. Returns true if all went OK.
public static boolean clearCacheFilesAndDirs()
Method used to clear/empty the cache by deleting all of stored files and dirs in getCacheDir() directory. Returns true if all went OK.
public static File getTempDir()
Returns a File representing temporary directory (app cache directory) on External Storage Drive if its available or based on context.getCacheDir() otherwise.
public static File getCacheDir()
Returns a File representing temporary directory (app cache directory) on External Storage Drive if its available or based on context.getCacheDir() otherwise.
public static File getCacheDir(Context context)
Returns a temporary directory (app cache directory) on External Storage Drive if its available or based on context.getCacheDir() otherwise.
public static String[] getAPKExpansionFiles(final int mainVersion, final int patchVersion)
Returns an array of all app expansion files. The path usually leads to sdcard/Android/obb/app_package. If mainVersion is given then patchVersion ignored and otherwise.
public static String[] getAPKExpansionFiles(final Context context, final int mainVersion, final int patchVersion)
Returns an array of all app expansion files. The path usually leads to sdcard/Android/obb/app_package. If mainVersion is given then patchVersion ignored and otherwise. This version uses given Context instead of Application one.
public static File getAPKExpansionFile(int mainVersion)
Returns the expansion file by its mainVersion. The path usually leads to sdcard/Android/obb/app_package.
public static File getAPKExpansionFile(Context context, int mainVersion)
Returns the expansion file by its mainVersion. The path usually leads to sdcard/Android/obb/app_package. This version uses given Context instead of Application one.
public static HashSet<String> getExternalMounts()
Returns a set of found external paths which could lead to sdcard or its emulation (for devices with no external SD card support). Also there are could be several external drives available on device: internal drive and external represented by inserted SD card.
public static HashSet<String> getStorageDirectories()
Returns all available SD-Cards in the system (including emulated).
This is Hack! Based on Android source code of version 4.3 (API 18) because there is no standard way to get it.