Context getCacheDir - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context getCacheDir method.

This code example shows how to use the following methods:checkCallingOrSelfPermission, getCacheDir
		File appCacheDir = null;
		if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
			appCacheDir = getExternalCacheDir(context);
		} 
		if (appCacheDir == null) {
			appCacheDir = context.getCacheDir();
		} 
		if (appCacheDir == null) {
			L.w("Can't define system cache directory! The app should be re-installed."); 
		} 
		return appCacheDir;
	} 
 
	/** 
	 * Returns individual application cache directory (for only image caching from ImageLoader). Cache directory will be 
	 * created on SD card <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is mounted and app has 
	 * appropriate permission. Else - Android defines cache directory on device's file system. 
	 * 
	 * @param context Application context 
	 * @return Cache {@link File directory} 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir, getSystemService
     *  
     * @param context 
     */ 
    public HttpImageGetter(Context context) {
        this.context = context;
        dir = context.getCacheDir();
        width = ((WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
                .getWidth();
        loading = new LoadingImageGetter(context, 24);
    } 
 
    private HttpImageGetter show(final TextView view, final CharSequence html) {
        if (TextUtils.isEmpty(html))
            return hide(view);
 
        try { 
            view.setText(html);
        } 
        catch (Exception e) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir, getFilesDir, getMainLooper
    // Dispatch a round of property updates, should only be called on UI thread 
 
    public static native void pollCourier(); 
 
    public static void init(Context ctx) {
        courier = new Handler(ctx.getMainLooper(), new Handler.Callback() {
                public boolean handleMessage(Message msg) {
                    pollCourier(); 
                    return true; 
                } 
            }); 
 
        coreInit(ctx.getFilesDir().getPath(), ctx.getCacheDir().getPath());
    } 
 
    public static void wakeupMainDispatcher() { 
        courier.sendEmptyMessage(0);
    } 
 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir, getExternalCacheDir, getPackageName
	 */ 
	public static File getExternalCacheDir(Context context)
	{ 
		if (AndroidVersionCheckUtils.hasFroyo()) 
		{ 
			return context.getExternalCacheDir();
		} 
		final String cacheDir = "/Android/data/" + context.getPackageName()
				+ "/cache/"; 
		return new File(Environment.getExternalStorageDirectory().getPath()
				+ cacheDir);
	} 
 
	/** 
	 * 检查如果外部存储器是内置的或是可移动的。 
	 *  
	 * @return 如果外部存储是可移动的(就像一个SD卡)返回为 true,否则false。 
	 */ 
	public static boolean isExternalStorageRemovable() 
	{ 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getApplicationContext, getCacheDir
    public WebImageCache(Context context) {
        // Set up in-memory cache store 
        memoryCache = new ConcurrentHashMap<String, SoftReference<Bitmap>>();
 
        // Set up disk cache store 
        Context appContext = context.getApplicationContext();
        diskCachePath = appContext.getCacheDir().getAbsolutePath() + DISK_CACHE_PATH;
 
        File outFile = new File(diskCachePath);
        outFile.mkdirs();
 
        diskCacheEnabled = outFile.exists();
 
        // Set up threadpool for image fetching tasks 
        writeThread = Executors.newSingleThreadExecutor();
    } 
 
    public Bitmap get(final String url) {
        Bitmap bitmap = null;
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir, getFilesDir
	public static String picPath(String size, int hash, Context context) {
		return picDir(hash, context) + size + ".jpg";
	} 
 
	public static String picDir(int hash, Context context) {
		File cacheDir = context.getCacheDir();
		if (cacheDir == null)
			cacheDir = context.getFilesDir();
		File picDir = new File(context.getCacheDir().getPath() + "/" + hash);
		picDir.mkdirs();
		return picDir.getPath();
	} 
 
	public static void cacheImage(String size, int hash, String url, Context context) {
		File outFile = new File(picPath(size, hash, context));
		if (outFile.exists())
			outFile.delete();
 
		downloadFile(url, outFile);
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:checkCallingOrSelfPermission, getCacheDir
		File appCacheDir = null;
		if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
			appCacheDir = getExternalCacheDir(context);
		} 
		if (appCacheDir == null) {
			appCacheDir = context.getCacheDir();
		} 
		if (appCacheDir == null) {
			L.w("Can't define system cache directory! The app should be re-installed."); 
		} 
		return appCacheDir;
	} 
 
	/** 
	 * Returns individual application cache directory (for only image caching 
	 * from ImageLoader). Cache directory will be created on SD card 
	 * <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is 
	 * mounted and app has appropriate permission. Else - Android defines cache 
	 * directory on device's file system. 
	 *  

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir
    protected File getExternalStorageDirectory() {
        return android.os.Environment.getExternalStorageDirectory();
    } 
 
    protected File preparePhoneCacheDir() {
        return context.getCacheDir();
    } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir
    assertThat(context.obtainStyledAttributes(null, null, 0, 0)).isNotNull();
  } 
 
  @Test 
  public void getCacheDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getCacheDir().exists());
  } 
 
  @Test 
  public void getExternalCacheDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getExternalCacheDir().exists());
  } 
 
  @Test 
  public void shouldWriteToCacheDir() throws Exception { 
    assertNotNull(context.getCacheDir());
    File cacheTest = new File(context.getCacheDir(), "__test__");
 
    assertThat(cacheTest.getAbsolutePath()).startsWith(System.getProperty("java.io.tmpdir"));
    assertThat(cacheTest.getAbsolutePath()).contains("android-cache");
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCacheDir
	 
	private final File tmpFile;
	private String filename;
	 
	public ExportToTempFileTask(Context context, long trackId) {
		super(context, trackId);
		try { 
			tmpFile = File.createTempFile("osm-upload", ".gpx", context.getCacheDir());
			Log.d(TAG, "Temporary file: " + tmpFile.getAbsolutePath());
		} catch (IOException ioe) {
			Log.e(TAG, "Could not create temporary file", ioe);
			throw new IllegalStateException("Could not create temporary file", ioe);
		} 
	} 
	 
	 
	@Override 
	protected File getExportDirectory(Date startDate) throws ExportTrackException {
		return tmpFile.getParentFile();
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Context getCacheDir Questions & Answers:

Other Context getCacheDir Examples

12:	            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"TempImages");
13:	        else
14:	            cacheDir=context.getCacheDir();
15:	        if(!cacheDir.exists())
16:	            cacheDir.mkdirs();

Read More

12:	        else
13:	            cacheDir=context.getCacheDir();
14:	        if(!cacheDir.exists())
15:	            cacheDir.mkdirs();
16:	    }

Read More

getCacheDir Method Overview
Returns the absolute path to the application specific cache directory on the filesystem.
See Code Examples for other Android Context Methods: