List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:com.joeyturczak.jtscanner.utils.Utility.java
public static void trimCache(Context context) { try {//from w w w. j ava 2 s . c om File dir = context.getCacheDir(); if (dir != null && dir.isDirectory()) { deleteDir(dir); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.corochann.androidtvapptutorial.recommendation.RecommendationBuilder.java
/** * returns file path to store background bitmap image (caching) * @param context/*from ww w . j a v a 2s . com*/ * @param notificationId * @return the file path of background image */ private static File getNotificationBackground(Context context, int notificationId) { Log.i(TAG, "getNotificationBackground: " + context.getCacheDir() + "tmp" + Integer.toString(notificationId) + ".png"); return new File(context.getCacheDir(), "tmp" + Integer.toString(notificationId) + ".png"); }
From source file:io.github.protino.codewatch.utils.FileProviderUtils.java
public static void shareBitmap(Context context, Bitmap bitmap) throws IOException { final String imageName = "/" + String.valueOf(System.currentTimeMillis()); //First save the bitmap to cache directory File directory = new File(context.getCacheDir(), CACHE_DIR_NAME); if (!directory.mkdirs()) { //delete all data under this folder deleteRecursive(directory);/* ww w . j a v a 2 s . c om*/ //recreate the directory directory = new File(context.getCacheDir(), CACHE_DIR_NAME); directory.mkdirs(); } FileOutputStream stream = new FileOutputStream(directory + imageName + IMAGE_EXTENSION); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); stream.flush(); stream.close(); //Now create uri through FileProvider File newFile = new File(directory, imageName + IMAGE_EXTENSION); Uri uri = FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, newFile); if (uri != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(uri, context.getContentResolver().getType(uri)); intent.setType("image/png"); intent.putExtra(Intent.EXTRA_STREAM, uri); context.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_app))); } }
From source file:Main.java
public static String getCachePath(Context context, String uniqueName) { String cachePath;//www. ja v a 2 s.c om if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return cachePath + File.separator + uniqueName; }
From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherUtils.java
private static File getTargetFile(Context context) { return new File(context.getCacheDir() + File.separator + sTargetFile); }
From source file:Main.java
public static File getDiskCacheDir(Context context, String fileName) { String cachePath;/* ww w . j av a 2 s . c om*/ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && !Environment.isExternalStorageRemovable()) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } Log.d("bonus", "cachePath = " + cachePath); return new File(cachePath + File.separator + fileName); }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;//from w w w.ja v a 2 s .c om if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return new File(cachePath + File.separator + uniqueName); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;//from w ww . ja v a 2s. c o m if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageEmulated()) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return new File(cachePath + File.separator + uniqueName); }
From source file:com.whiuk.philip.opensmime.PathConverter.java
private static File copyToTempFile(Context context, InputStream inputStream) throws IOException { File outputDir = context.getCacheDir(); // context being the Activity pointer File outputFile = File.createTempFile("import", ".tmp", outputDir); FileUtils.copyInputStreamToFile(inputStream, outputFile); return outputFile; }
From source file:Main.java
/** * Get disk cache directory// w w w . java2 s. co m * * @param ctx * @param uniqueName Unique name for caching directory, use it separate different types of cached files. eg: bitmap,strings,css,files etc. * @return cache directory */ public static File getDiskCacheDir(Context ctx, String uniqueName) { String cachePath; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { cachePath = ctx.getExternalCacheDir().getPath(); } else { cachePath = ctx.getCacheDir().getPath(); } return new File(cachePath, uniqueName); }