Java Code Examples for android.content.Context#getExternalCacheDirs()
The following examples show how to use
android.content.Context#getExternalCacheDirs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UriUtil.java From Common with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static String getPathToNonPrimaryVolume(Context context, String tag) { File[] volumes = context.getExternalCacheDirs(); if (volumes != null) { for (File volume : volumes) { if (volume != null) { String path = volume.getAbsolutePath(); if (path != null) { int index = path.indexOf(tag); if (index != -1) { return path.substring(0, index) + tag; } } } } } return null; }
Example 2
Source File: FileUtils.java From OsmGo with MIT License | 6 votes |
private static String getPathToNonPrimaryVolume(Context context, String tag) { File[] volumes = context.getExternalCacheDirs(); if (volumes != null) { for (File volume : volumes) { if (volume != null) { String path = volume.getAbsolutePath(); if (path != null) { int index = path.indexOf(tag); if (index != -1) { return path.substring(0, index) + tag; } } } } } return null; }
Example 3
Source File: CacheManager.java From RedReader with GNU General Public License v3.0 | 6 votes |
public static List<File> getCacheDirs(Context context) { final ArrayList<File> dirs = new ArrayList<>(); dirs.add(context.getCacheDir()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { for(final File dir : context.getExternalCacheDirs()) { if(dir != null) { dirs.add(dir); } } } else { final File extDir = context.getExternalCacheDir(); if (extDir != null) { dirs.add(extDir); } } return dirs; }
Example 4
Source File: ImageMagickUtils.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
public static void setCacheDir(Context context) { File maxDir = null; long maxSpace = -1; String path; File[] dirs = context.getExternalCacheDirs(); for (int k = 0; k < dirs.length; ++k) { File dir = dirs[k]; long dirFreeSpace = dir.getFreeSpace(); // testing: path = dir.getAbsolutePath(); Log.d(TAG, "- #" + k + " cache path: " + path); if (dirFreeSpace > maxSpace) { maxSpace = dirFreeSpace; maxDir = dir; } } if (maxDir != null) { path = maxDir.getAbsolutePath(); Log.d(TAG, "- best cache path: " + path); Magick.setCacheDir(path); } else Log.d(TAG, "- best cache dir null"); }
Example 5
Source File: FileProvider.java From AndPermission with Apache License 2.0 | 5 votes |
public static File[] getExternalCacheDirs(Context context) { if (Build.VERSION.SDK_INT >= 19) { return context.getExternalCacheDirs(); } else { return new File[] {context.getExternalCacheDir()}; } }
Example 6
Source File: IO.java From PocketMaps with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static ArrayList<String> listSelectionPathsLollipop(Context context, boolean cacheDir) { File files[]; if (cacheDir) { files = context.getExternalCacheDirs(); } else { files = context.getExternalMediaDirs(); } final ArrayList<String> items = new ArrayList<String>(); items.add(getDefaultBaseDirectory(context).getPath()); for (File curFile : files) { if (curFile == null) { // Regarding to android javadoc this may be possible. continue; } String mountState = Environment.getExternalStorageState(curFile); if (mountState.equals(Environment.MEDIA_MOUNTED) || mountState.equals(Environment.MEDIA_SHARED)) { items.add(curFile.getPath()); } } return items; }
Example 7
Source File: FileProvider.java From attach with GNU General Public License v3.0 | 4 votes |
/** * Parse and return {@link PathStrategy} for given authority as defined in * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}. * * @see #getPathStrategy(Context, String) */ private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException { final SimplePathStrategy strat = new SimplePathStrategy(authority); final ProviderInfo info = context.getPackageManager() .resolveContentProvider(authority, PackageManager.GET_META_DATA); final XmlResourceParser in = info.loadXmlMetaData( context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS); if (in == null) { throw new IllegalArgumentException( "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data"); } int type; while ((type = in.next()) != END_DOCUMENT) { if (type == START_TAG) { final String tag = in.getName(); final String name = in.getAttributeValue(null, ATTR_NAME); String path = in.getAttributeValue(null, ATTR_PATH); File target = null; if (TAG_ROOT_PATH.equals(tag)) { target = DEVICE_ROOT; } else if (TAG_FILES_PATH.equals(tag)) { target = context.getFilesDir(); } else if (TAG_CACHE_PATH.equals(tag)) { target = context.getCacheDir(); } else if (TAG_EXTERNAL.equals(tag)) { target = Environment.getExternalStorageDirectory(); } else if (TAG_EXTERNAL_FILES.equals(tag)) { File[] externalFilesDirs; if (Build.VERSION.SDK_INT >= 19) { externalFilesDirs = context.getExternalFilesDirs(null); } else { externalFilesDirs = new File[] { context.getExternalFilesDir(null) }; } if (externalFilesDirs.length > 0) { target = externalFilesDirs[0]; } } else if (TAG_EXTERNAL_CACHE.equals(tag)) { File[] externalCacheDirs; if (Build.VERSION.SDK_INT >= 19) { externalCacheDirs = context.getExternalCacheDirs(); } else { externalCacheDirs = new File[] { context.getExternalCacheDir() }; } if (externalCacheDirs.length > 0) { target = externalCacheDirs[0]; } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && TAG_EXTERNAL_MEDIA.equals(tag)) { File[] externalMediaDirs = context.getExternalMediaDirs(); if (externalMediaDirs.length > 0) { target = externalMediaDirs[0]; } } if (target != null) { strat.addRoot(name, buildPath(target, path)); } } } return strat; }
Example 8
Source File: ContextCompatKitKat.java From adt-leanback-support with Apache License 2.0 | 4 votes |
public static File[] getExternalCacheDirs(Context context) { return context.getExternalCacheDirs(); }
Example 9
Source File: ContextCompatKitKat.java From V.FlyoutTest with MIT License | 4 votes |
public static File[] getExternalCacheDirs(Context context) { return context.getExternalCacheDirs(); }
Example 10
Source File: ContextCompatKitKat.java From guideshow with MIT License | 4 votes |
public static File[] getExternalCacheDirs(Context context) { return context.getExternalCacheDirs(); }