List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:com.ndn.menurandom.ImageDownloader.java
private void initialize(Context context) { mContext = context;/*w w w . jav a 2 s.co m*/ if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) mCacheDir = new File(android.os.Environment.getExternalStorageDirectory(), mStrCacheDir); else mCacheDir = context.getCacheDir(); if (!mCacheDir.exists()) { mCacheDir.mkdirs(); } }
From source file:com.cloudstudio.camera.ForegroundCameraLauncher.java
/** * Determine if we can use the SD Card to store the temporary file. If not * then use the internal cache directory. * /* w w w .j a v a 2 s.com*/ * @return the absolute path of where to store the file */ private String getTempDirectoryPath(Context ctx) { File cache = null; // SD Card Mounted if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + ctx.getPackageName() + "/cache/"); } // Use internal storage else { cache = ctx.getCacheDir(); } Log.d("camera", "cacha path:" + cache.getAbsolutePath()); // Create the cache directory if it doesn't exist if (!cache.exists()) { cache.mkdirs(); } return cache.getAbsolutePath(); }
From source file:org.gdg.frisbee.android.cache.ModelCache.java
ModelCache(Context context) { if (context != null) { // Make sure we have the application context context = context.getApplicationContext(); mTempDir = context.getCacheDir(); mResources = context.getResources(); }// w w w . jav a 2 s. co m mGson = new GsonBuilder().registerTypeAdapter(DateTime.class, new DateTimeDeserializer()) .registerTypeAdapter(DateTime.class, new DateTimeSerializer()).create(); }
From source file:com.swater.meimeng.activity.oomimg.ImageCache.java
/** * Generally, it's best to use the shared image cache using {@link #getInstance(android.content.Context)}. Use * this if you want to customize a cache or keep it separate. * * @param context/*ww w . ja va2 s . c o m*/ * @param format * @param quality */ public ImageCache(Context context, CompressFormat format, int quality) { super(context.getCacheDir(), null, getExtension(format)); if (USE_APACHE_NC) { hc = getHttpClient(); } else { hc = null; } mRes = context.getResources(); mCompressFormat = format; mQuality = quality; }
From source file:com.developer4droid.contactslister.backend.image_load.EnhancedImageDownloader.java
public EnhancedImageDownloader(Context context) { resources = context.getResources();//from ww w . j a v a2 s. c om // Find the dir to save cached images if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) cacheDir = new File(android.os.Environment.getExternalStorageDirectory(), getApplicationCacheDir(context.getPackageName())); else cacheDir = context.getCacheDir(); if (!cacheDir.exists()) cacheDir.mkdirs(); }
From source file:com.daiv.android.twitter.services.SendTweet.java
public boolean sendTweet(AppSettings settings, Context context) { try {/*from w ww.j ava 2s .com*/ Twitter twitter = getTwitter(); if (remainingChars < 0 && !pwiccer) { // twitlonger goes here TwitLongerHelper helper = new TwitLongerHelper(message, twitter); helper.setInReplyToStatusId(tweetId); return helper.createPost() != 0; } else { twitter4j.StatusUpdate reply = new twitter4j.StatusUpdate(message); reply.setInReplyToStatusId(tweetId); if (!attachedUri.equals("")) { File outputDir = context.getCacheDir(); // context being the Activity pointer File f = File.createTempFile("compose", "picture", outputDir); Bitmap bitmap = getBitmapToSend(Uri.parse(attachedUri), context); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); byte[] bitmapdata = bos.toByteArray(); FileOutputStream fos = new FileOutputStream(f); fos.write(bitmapdata); fos.flush(); fos.close(); if (!settings.twitpic) { reply.setMedia(f); twitter.updateStatus(reply); return true; } else { TwitPicHelper helper = new TwitPicHelper(twitter, message, f, context); helper.setInReplyToStatusId(tweetId); return helper.createPost() != 0; } } else { // no picture twitter.updateStatus(reply); return true; } } } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:com.klinker.android.twitter.services.SendTweet.java
public boolean sendTweet(AppSettings settings, Context context) { try {//from www. j a v a 2 s . c om Twitter twitter = Utils.getTwitter(context, settings); if (remainingChars < 0 && !pwiccer) { // twitlonger goes here TwitLongerHelper helper = new TwitLongerHelper(message, twitter); helper.setInReplyToStatusId(tweetId); return helper.createPost() != 0; } else { twitter4j.StatusUpdate reply = new twitter4j.StatusUpdate(message); reply.setInReplyToStatusId(tweetId); if (!attachedUri.equals("")) { File outputDir = context.getCacheDir(); // context being the Activity pointer File f = File.createTempFile("compose", "picture", outputDir); Bitmap bitmap = getBitmapToSend(Uri.parse(attachedUri), context); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); byte[] bitmapdata = bos.toByteArray(); FileOutputStream fos = new FileOutputStream(f); fos.write(bitmapdata); fos.flush(); fos.close(); if (!settings.twitpic) { reply.setMedia(f); twitter.updateStatus(reply); return true; } else { TwitPicHelper helper = new TwitPicHelper(twitter, message, f, context); helper.setInReplyToStatusId(tweetId); return helper.createPost() != 0; } } else { // no picture twitter.updateStatus(reply); return true; } } } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:utils.bobo.com.boboutils.App.appwidget.CustomViewFileProvider.java
/** * Parse and return {@link PathStrategy} for given authority as defined in * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}. * * @see #getPathStrategy(Context, String) *//* w w w . j av a 2 s.c o m*/ 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 = buildPath(DEVICE_ROOT, path); } else if (TAG_FILES_PATH.equals(tag)) { target = buildPath(context.getFilesDir(), path); } else if (TAG_CACHE_PATH.equals(tag)) { target = buildPath(context.getCacheDir(), path); } else if (TAG_EXTERNAL.equals(tag)) { target = buildPath(Environment.getExternalStorageDirectory(), path); } if (target != null) { strat.addRoot(name, target); } } } return strat; }
From source file:com.hippo.content.FileProvider.java
/** * Parse and return {@link PathStrategy} for given authority as defined in * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}. * * @see #getPathStrategy(Context, String) *//*from ww w . j a v a 2 s . c o m*/ 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 = ContextCompat.getExternalFilesDirs(context, null); if (externalFilesDirs.length > 0) { target = externalFilesDirs[0]; } } else if (TAG_EXTERNAL_CACHE.equals(tag)) { File[] externalCacheDirs = ContextCompat.getExternalCacheDirs(context); if (externalCacheDirs.length > 0) { target = externalCacheDirs[0]; } } if (target != null) { strat.addRoot(name, buildPath(target, path)); } } } return strat; }
From source file:com.mattprecious.telescope.FileProvider.java
/** * Parse and return {@link PathStrategy} for given authority as defined in * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}. * * @see #getPathStrategy(Context, String) *//*from w ww .j a va2 s . c om*/ 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 = buildPath(DEVICE_ROOT, path); } else if (TAG_FILES_PATH.equals(tag)) { target = buildPath(context.getFilesDir(), path); } else if (TAG_CACHE_PATH.equals(tag)) { target = buildPath(context.getCacheDir(), path); } else if (TAG_EXTERNAL.equals(tag)) { target = buildPath(Environment.getExternalStorageDirectory(), path); } else if (TAG_EXTERNAL_APP.equals(tag)) { try { // This sometimes causes an exception on API level 19 // Just avoid this specific file provider, so we can try to keep going target = buildPath(context.getExternalFilesDir(null), path); } catch (NullPointerException npe) { npe.printStackTrace(); } } if (target != null) { strat.addRoot(name, target); } } } return strat; }