List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:org.sogrey.frame.utils.FileUtil.java
/** * ???./*from w ww. java2 s . c o m*/ * * @param context * the context */ public static void initFileDir(Context context) { PackageInfo info = AppUtil.getPackageInfo(context); // . String downloadRootPath = File.separator + AppConfig.DOWNLOAD_ROOT_DIR + File.separator + info.packageName + File.separator; // . String imageDownloadPath = downloadRootPath + AppConfig.DOWNLOAD_IMAGE_DIR + File.separator; // . String fileDownloadPath = downloadRootPath + AppConfig.DOWNLOAD_FILE_DIR + File.separator; // . String cacheDownloadPath = downloadRootPath + AppConfig.CACHE_DIR + File.separator; // DB. String dbDownloadPath = downloadRootPath + AppConfig.DB_DIR + File.separator; // . String logPath = downloadRootPath + AppConfig.LOG_DIR + File.separator; try { if (!isCanUseSD()) { downloadRootDir = context.getFilesDir().getPath(); cacheDownloadDir = context.getCacheDir().getPath(); imageDownloadDir = downloadRootDir; fileDownloadDir = downloadRootDir; dbDownloadDir = downloadRootDir; logDir = downloadRootDir; return; } else { File root = Environment.getExternalStorageDirectory(); File downloadDir = new File(root.getAbsolutePath() + downloadRootPath); if (!downloadDir.exists()) { downloadDir.mkdirs(); } downloadRootDir = downloadDir.getPath(); File cacheDownloadDirFile = new File(root.getAbsolutePath() + cacheDownloadPath); if (!cacheDownloadDirFile.exists()) { cacheDownloadDirFile.mkdirs(); } cacheDownloadDir = cacheDownloadDirFile.getPath(); File imageDownloadDirFile = new File(root.getAbsolutePath() + imageDownloadPath); if (!imageDownloadDirFile.exists()) { imageDownloadDirFile.mkdirs(); } imageDownloadDir = imageDownloadDirFile.getPath(); File fileDownloadDirFile = new File(root.getAbsolutePath() + fileDownloadPath); if (!fileDownloadDirFile.exists()) { fileDownloadDirFile.mkdirs(); } fileDownloadDir = fileDownloadDirFile.getPath(); File dbDownloadDirFile = new File(root.getAbsolutePath() + dbDownloadPath); if (!dbDownloadDirFile.exists()) { dbDownloadDirFile.mkdirs(); } dbDownloadDir = dbDownloadDirFile.getPath(); File logDirFile = new File(root.getAbsolutePath() + logPath); if (!logDirFile.exists()) { logDirFile.mkdirs(); } logDir = logDirFile.getPath(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Enables http cache. (when using webview for example) * /* w ww .ja va2 s .c o m*/ * @param ctx */ public static void web_enableHttpResponseCache(Context ctx) { try { long httpCacheSize = HTTP_CACHE_SIZE; File httpCacheDir = new File(ctx.getCacheDir(), "http"); Class.forName("android.net.http.HttpResponseCache").getMethod("install", File.class, long.class) .invoke(null, httpCacheDir, httpCacheSize); } catch (Exception e) { if (LOG_ENABLE) Log.e(TAG, "Http Response cache could not be initialized [" + e.getMessage() + "]", e); } }
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Delete cache files./*from w ww . j ava2 s.c om*/ */ private void deleteCaches() { ArrayList<PackageInfo> uninstallList = new ArrayList<PackageInfo>(); for (PackingItem packageItem : m_list) { if (packageItem.m_checked) { try { PackageInfo packInfo = packageItem.m_packInfo; long cacheSize = 0; long fileCount = 0; Context mContext = getActivity().createPackageContext(packInfo.packageName, Context.CONTEXT_IGNORE_SECURITY); File cacheDirectory = null; Utils.DirSizeCount cacheDirSize = null; if (mContext.getCacheDir() != null) { cacheDirectory = mContext.getCacheDir(); // cacheSize = cacheDirectory.length()/1024; cacheDirSize = Utils.getDirectorySize(cacheDirectory); if (cacheDirSize == null) { // Cache is not readable or empty, // Try and map cache dir to one of the sd storage paths for (String storageDir : m_storageDirs) { try { File cacheDirectory2 = new File(cacheDirectory.getCanonicalPath() .replace("/data/data", storageDir + "/Android/data")); if (cacheDirectory2.exists()) { cacheDirectory = cacheDirectory2; cacheDirSize = Utils.getDirectorySize(cacheDirectory); break; } } catch (Exception ex) { m_log.d(ex.getMessage()); } } } if (cacheDirSize != null) { List<String> deletedFiles = Utils.deleteFiles(cacheDirectory); if (deletedFiles == null || deletedFiles.isEmpty()) { } else { String fileMsg = TextUtils.join("\n", deletedFiles.toArray()); Toast.makeText(getContext(), packageItem.m_appName + "\n" + fileMsg, Toast.LENGTH_LONG).show(); } } } } catch (Exception ex) { m_log.e(ex.getLocalizedMessage()); } } } // ((BaseExpandableListAdapter) m_listView.getExpandableListAdapter()).notifyDataSetChanged(); // updateList(); loadPackages(); }
From source file:org.mariotaku.twidere.util.Utils.java
public static File getBestCacheDir(final Context context, final String cache_dir_name) { final File ext_cache_dir = EnvironmentAccessor.getExternalCacheDir(context); if (ext_cache_dir != null && ext_cache_dir.isDirectory()) { final File cache_dir = new File(ext_cache_dir, cache_dir_name); if (cache_dir.isDirectory() || cache_dir.mkdirs()) return cache_dir; }/* w w w .j a v a 2s . c o m*/ return new File(context.getCacheDir(), cache_dir_name); }
From source file:org.chromium.android_webview.test.AwSettingsTest.java
@SmallTest @Feature({ "AndroidWebView", "Preferences" }) public void testBlockNetworkLoadsWithHttpResources() throws Throwable { final TestAwContentsClient contentClient = new TestAwContentsClient(); final AwTestContainerView testContainer = createAwTestContainerViewOnMainSync(contentClient); final AwContents awContents = testContainer.getAwContents(); final AwSettings awSettings = getAwSettingsOnUiThread(awContents); awSettings.setJavaScriptEnabled(true); ImagePageGenerator generator = new ImagePageGenerator(0, false); TestWebServer webServer = null;/* w w w . j av a 2 s. co m*/ String fileName = null; try { // Set up http image. webServer = new TestWebServer(false); final String httpPath = "/image.png"; final String imageUrl = webServer.setResponseBase64(httpPath, generator.getImageSourceNoAdvance(), CommonResources.getImagePngHeaders(true)); // Set up file html that loads http iframe. String pageHtml = "<img src='" + imageUrl + "' " + "onload=\"document.title='img_onload_fired';\" " + "onerror=\"document.title='img_onerror_fired';\" />"; Context context = getInstrumentation().getTargetContext(); fileName = context.getCacheDir() + "/block_network_loads_test.html"; TestFileUtil.deleteFile(fileName); // Remove leftover file if any. TestFileUtil.createNewHtmlFile(fileName, "unset", pageHtml); // Actual test. Blocking should trigger onerror handler. awSettings.setBlockNetworkLoads(true); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), "file:///" + fileName); assertEquals(0, webServer.getRequestCount(httpPath)); assertEquals("img_onerror_fired", getTitleOnUiThread(awContents)); // Unblock should load normally. awSettings.setBlockNetworkLoads(false); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), "file:///" + fileName); assertEquals(1, webServer.getRequestCount(httpPath)); assertEquals("img_onload_fired", getTitleOnUiThread(awContents)); } finally { if (fileName != null) TestFileUtil.deleteFile(fileName); if (webServer != null) webServer.shutdown(); } }
From source file:org.codarama.haxsync.services.ContactsSyncAdapterService.java
@SuppressWarnings("unused") private static void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName() + "_preferences", MODE_MULTI_PROCESS);// w w w. ja v a 2 s . com mContentResolver = context.getContentResolver(); FacebookUtil.refreshPermissions(context); //TODO: Clean up stuff that isn't needed anymore since Graph API boolean cropPhotos = true; boolean sync = prefs.getBoolean("sync_status", true); boolean syncNew = prefs.getBoolean("status_new", true); boolean syncLocation = prefs.getBoolean("sync_location", true); boolean syncSelf = prefs.getBoolean("sync_self", false); boolean imageDefault = prefs.getBoolean("image_primary", true); boolean oldStatus = sync && (!syncNew || (Build.VERSION.SDK_INT < 15)); boolean faceDetect = true; boolean root = prefs.getBoolean("root_enabled", false); int rootSize = 512; if (FacebookUtil.authorize(context, account)) { HashMap<String, SyncEntry> localContacts = getLocalContacts(account); HashMap<String, Long> names = loadPhoneContacts(context); HashMap<String, Long> uids = loadHTCData(context); //Log.i("CONTACTS", names.toString()); boolean phoneOnly = prefs.getBoolean("phone_only", true); /*if (phoneOnly){ names = loadPhoneContacts(context); }*/ boolean wifiOnly = prefs.getBoolean("wifi_only", false); boolean syncEmail = prefs.getBoolean("sync_facebook_email", false); boolean syncBirthday = prefs.getBoolean("sync_contact_birthday", true); boolean force = prefs.getBoolean("force_dl", false); boolean google = prefs.getBoolean("update_google_photos", false); boolean ignoreMiddleaNames = prefs.getBoolean("ignore_middle_names", false); boolean addMeToFriends = prefs.getBoolean("add_me_to_friends", false); Log.i("google", String.valueOf(google)); int fuzziness = Integer.parseInt(prefs.getString("fuzziness", "2")); Set<String> addFriends = prefs.getStringSet("add_friends", new HashSet<String>()); Log.i(TAG, "phone_only: " + Boolean.toString(phoneOnly)); Log.i(TAG, "wifi_only: " + Boolean.toString(wifiOnly)); Log.i(TAG, "is wifi: " + Boolean.toString(DeviceUtil.isWifi(context))); Log.i(TAG, "phone contacts: " + names.toString()); Log.i(TAG, "using old status api: " + String.valueOf(oldStatus)); Log.i(TAG, "ignoring middle names : " + String.valueOf(ignoreMiddleaNames)); Log.i(TAG, "add me to friends : " + String.valueOf(addMeToFriends)); boolean chargingOnly = prefs.getBoolean("charging_only", false); int maxsize = BitmapUtil.getMaxSize(context.getContentResolver()); File cacheDir = context.getCacheDir(); Log.i("CACHE DIR", cacheDir.getAbsolutePath()); Log.i("MAX IMAGE SIZE", String.valueOf(maxsize)); if (!((wifiOnly && !DeviceUtil.isWifi(context)) || (chargingOnly && !DeviceUtil.isCharging(context)))) { try { if (syncSelf) { addSelfContact(account, maxsize, cropPhotos, faceDetect, force, root, rootSize, cacheDir, google); } List<FacebookGraphFriend> friends = FacebookUtil.getFriends(maxsize, addMeToFriends); for (FacebookGraphFriend friend : friends) { String uid = friend.getUserName(); String friendName = friend.getName(ignoreMiddleaNames); if (friendName != null && uid != null) { String match = matches(names.keySet(), friendName, fuzziness); if (!(phoneOnly && (match == null) && !uids.containsKey(uid)) || addFriends.contains(friendName)) { // STEP 1. Add contact - if the contact is not part of the HTCData records and does not match any // of the fuzziness names we add them to the list of contacts with the intention to make them available // for manual merge (I guess) if (localContacts.get(uid) == null) { //String name = friend.getString("name"); //Log.i(TAG, name + " already on phone: " + Boolean.toString(names.contains(name))); addContact(account, friendName, uid); SyncEntry entry = new SyncEntry(); Uri rawContactUr = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type) .appendQueryParameter(RawContacts.Data.DATA1, uid).build(); Cursor c = mContentResolver.query(rawContactUr, new String[] { BaseColumns._ID }, null, null, null); c.moveToLast(); long id = c.getLong(c.getColumnIndex(BaseColumns._ID)); c.close(); // Log.i("ID", Long.toString(id)); entry.raw_id = id; localContacts.put(uid, entry); if (uids.containsKey(uid)) { ContactUtil.merge(context, uids.get(uid), id); } else if (names.containsKey(match)) { ContactUtil.merge(context, names.get(match), id); } //localContacts = loadContacts(accounts, context); } // STEP 2. Set contact photo SyncEntry contact = localContacts.get(uid); updateContactPhoto(contact.raw_id, friend.getPicTimestamp(), maxsize, cropPhotos, friend.getPicURL(), faceDetect, force, root, rootSize, cacheDir, google, imageDefault); if (syncEmail && !FacebookUtil.RESPECT_FACEBOOK_POLICY) ContactUtil.addEmail(context, contact.raw_id, friend.getEmail()); if (syncLocation && !FacebookUtil.RESPECT_FACEBOOK_POLICY) { ContactUtil.updateContactLocation(contact.raw_id, friend.getLocation()); } if (oldStatus && !FacebookUtil.RESPECT_FACEBOOK_POLICY) { ArrayList<Status> statuses = friend.getStatuses(); if (statuses.size() >= 1) { updateContactStatus(contact.raw_id, statuses.get(0).getMessage(), statuses.get(0).getTimestamp()); } } if (syncBirthday && !FacebookUtil.RESPECT_FACEBOOK_POLICY) { String birthday = friend.getBirthday(); if (birthday != null) { ContactUtil.addBirthday(contact.raw_id, birthday); } } } } } } catch (Exception e) { // FIXME catching the generic Exception class is not hte best thing to do Log.e("ERROR", e.toString()); } if (root) { try { RootUtil.refreshContacts(); } catch (ShellException e) { Log.e("Error", e.getLocalizedMessage()); } } if (force) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("force_dl", false); editor.commit(); } } else { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("missed_contact_sync", true); editor.commit(); } } }
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Load installed (user or system) packages. * * TODO - include/*from w ww .j ava 2 s .c om*/ * /data/local/tmp * /sdcard/local/tmp ? * /storage/sdcardx/LOST.DIR/ * /sdcard/download * */ void loadCachedPackages() { try { // m_pkgUninstallBtn.setText(R.string.package_uninstall); m_uninstallResId = R.string.package_del_cache; m_pkgUninstallBtn.post(new Runnable() { @Override public void run() { updateUninstallBtn(); } }); m_workList = new ArrayList<PackingItem>(); // PackageManager.GET_SIGNATURES | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS; int flags1 = PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.GET_INTENT_FILTERS; int flags2 = PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES; int flags3 = PackageManager.GET_META_DATA; int flags4 = 0; List<PackageInfo> packList = getActivity().getPackageManager().getInstalledPackages(flags1); /* packList = mergePackages(packList, getActivity().getPackageManager().getInstalledPackages(flags2)); packList = mergePackages(packList, getActivity().getPackageManager().getInstalledPackages(flags3)); packList = mergePackages(packList, getActivity().getPackageManager().getInstalledPackages(flags4)); */ if (packList != null) for (int idx = 0; idx < packList.size(); idx++) { PackageInfo packInfo = packList.get(idx); long cacheSize = 0; long fileCount = 0; if (packInfo == null || packInfo.lastUpdateTime <= 0) { continue; // Bad package } Context pkgContext; try { m_log.d(String.format("%3d/%d : %s", idx, packList.size(), packInfo.packageName)); pkgContext = getActivity().createPackageContext(packInfo.packageName, Context.CONTEXT_IGNORE_SECURITY); } catch (Exception ex) { m_log.e(ex.getLocalizedMessage()); continue; // Bad package } File cacheDirectory = null; Utils.DirSizeCount cacheDirSize = null; if (pkgContext.getCacheDir() != null) { cacheDirectory = pkgContext.getCacheDir(); } else { // cacheDirectory = new File(mContext.getPackageResourcePath()); if (pkgContext.getFilesDir() != null) { String dataPath = pkgContext.getFilesDir().getPath(); // "/data/data/" cacheDirectory = new File(dataPath, pkgContext.getPackageName() + "/cache"); } } if (cacheDirectory != null) { // cacheSize = cacheDirectory.length()/1024; cacheDirSize = Utils.getDirectorySize(cacheDirectory); if (true) { // Cache is not readable or empty, // Try and map cache dir to one of the sd storage paths for (String storageDir : m_storageDirs) { try { File cacheDirectory2 = new File(cacheDirectory.getCanonicalPath() .replace("/data/data", storageDir + "/Android/data")); if (cacheDirectory2.exists()) { cacheDirectory = cacheDirectory2; Utils.DirSizeCount dirSize = Utils.getDirectorySize(cacheDirectory2); if (cacheDirSize == null || dirSize.size > cacheDirSize.size) { cacheDirSize = dirSize; cacheDirectory = cacheDirectory2; } } } catch (Exception ex) { m_log.d(ex.getMessage()); } } } } else { m_log.d(packInfo.packageName + " missing cache dir"); } Utils.DirSizeCount datDirSize = null; if (packInfo.applicationInfo.dataDir != null) { try { datDirSize = Utils.getDirectorySize(new File(packInfo.applicationInfo.dataDir)); } catch (Exception ex) { } } /* Method getPackageSizeInfo; try { getPackageSizeInfo = getActivity().getPackageManager().getClass().getMethod( "getPackageSizeInfo", String.class, Class.forName("android.content.pm.IPackageStatsObserver")); getPackageSizeInfo.invoke(getActivity().getPackageManager(), packInfo.packageName, new IPackageStatsObserver() { @Override public void onGetStatsCompleted( PackageStats pStats, boolean succeeded) throws RemoteException { totalSize = totalSize + pStats.cacheSize; } } ); } catch (Exception e) { continue; } */ /* if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) */ { ArrayListPairString pkgList = new ArrayListPairString(); String appName = "unknown"; try { appName = packInfo.applicationInfo.loadLabel(getActivity().getPackageManager()) .toString().trim(); } catch (Exception ex) { m_log.e(ex.getLocalizedMessage()); } long pkgSize = 0; addList(pkgList, "Version", packInfo.versionName); addList(pkgList, "TargetSDK", String.valueOf(packInfo.applicationInfo.targetSdkVersion)); String installTyp = "auto"; if (Build.VERSION.SDK_INT >= 21) { switch (packInfo.installLocation) { case PackageInfo.INSTALL_LOCATION_AUTO: break; case PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY: installTyp = "internal"; break; case PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL: installTyp = "external"; break; } } addList(pkgList, "Install", installTyp); // Add application info. try { addList(pkgList, "Allow Backup", String.valueOf((packInfo.applicationInfo.flags & FLAG_ALLOW_BACKUP) != 0)); addList(pkgList, "Debuggable", String.valueOf( (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0)); addList(pkgList, "External Storage", String.valueOf( (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0)); String themeName = getResourceName(packInfo, packInfo.applicationInfo.theme); if (!TextUtils.isEmpty(themeName)) addList(pkgList, "Theme", themeName); } catch (Exception ex) { Log.d("foo", ex.getMessage()); } try { File file = new File(packInfo.applicationInfo.sourceDir); pkgSize = file.length(); } catch (Exception ex) { } addList(pkgList, "Apk File", packInfo.applicationInfo.publicSourceDir); addList(pkgList, "Apk Size", NumberFormat.getNumberInstance(Locale.getDefault()).format(pkgSize)); addList(pkgList, "Src Dir", packInfo.applicationInfo.sourceDir); addList(pkgList, "lib Dir", packInfo.applicationInfo.nativeLibraryDir); addList(pkgList, "dat Dir", packInfo.applicationInfo.dataDir); if (null != datDirSize) { addList(pkgList, "* Dir Size", NumberFormat.getNumberInstance(Locale.getDefault()).format(datDirSize.size)); addList(pkgList, "* File Count", NumberFormat.getNumberInstance(Locale.getDefault()).format(datDirSize.count)); } if (null != cacheDirectory) { addList(pkgList, "Cache", cacheDirectory.getCanonicalPath()); if (null != cacheDirSize) { cacheSize = cacheDirSize.size; addList(pkgList, "* Dir Size", NumberFormat.getNumberInstance(Locale.getDefault()) .format(cacheDirSize.size)); addList(pkgList, "* File Count", NumberFormat .getNumberInstance(Locale.getDefault()).format(cacheDirSize.count)); } } if (null != packInfo.applicationInfo.sharedLibraryFiles && packInfo.applicationInfo.sharedLibraryFiles.length != 0) { addList(pkgList, "ShareLibs", NumberFormat.getNumberInstance(Locale.getDefault()) .format(packInfo.applicationInfo.sharedLibraryFiles.length)); for (String shrLibStr : packInfo.applicationInfo.sharedLibraryFiles) { addList(pkgList, " ", shrLibStr); } } if (true) { // packInfo.configPreferences; use with flag= GET_CONFIGURATIONS; // packInfo.providers use with GET_PROVIDERS; List<IntentFilter> outFilters = new ArrayList<IntentFilter>(); List<ComponentName> outActivities = new ArrayList<ComponentName>(); int num = getActivity().getPackageManager().getPreferredActivities(outFilters, outActivities, packInfo.packageName); if (num > 0) { addList(pkgList, "Preferred #", String.valueOf(num)); } } /* if (null != cacheDirectory) */ // if (cacheDirSize != null) { m_workList.add(new PackingItem(packInfo.packageName.trim(), pkgList, packInfo, cacheSize, appName)); } } } } catch (Exception ex) { m_log.e(ex.getMessage()); } }
From source file:de.vanita5.twittnuker.util.Utils.java
public static File getInternalCacheDir(final Context context, final String cacheDirName) { if (context == null) throw new NullPointerException(); final File cacheDir = new File(context.getCacheDir(), cacheDirName); if (cacheDir.isDirectory() || cacheDir.mkdirs()) return cacheDir; return new File(context.getCacheDir(), cacheDirName); }
From source file:com.dwdesign.tweetings.util.Utils.java
public static File getBestCacheDir(final Context context, final String cache_dir_name) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { final File ext_cache_dir = GetExternalCacheDirAccessor.getExternalCacheDir(context); if (ext_cache_dir != null && ext_cache_dir.isDirectory()) { final File cache_dir = new File(ext_cache_dir, cache_dir_name); if (cache_dir.isDirectory() || cache_dir.mkdirs()) return cache_dir; }/*w ww . jav a 2s .c o m*/ } else { final File ext_storage_dir = Environment.getExternalStorageDirectory(); if (ext_storage_dir != null && ext_storage_dir.isDirectory()) { final String ext_cache_path = ext_storage_dir.getAbsolutePath() + "/Android/data/" + context.getPackageName() + "/cache/"; final File cache_dir = new File(ext_cache_path, cache_dir_name); if (cache_dir.isDirectory() || cache_dir.mkdirs()) return cache_dir; } } return new File(context.getCacheDir(), cache_dir_name); }
From source file:de.vanita5.twittnuker.util.Utils.java
public static File getBestCacheDir(final Context context, final String cacheDirName) { if (context == null) throw new NullPointerException(); final File extCacheDir; try {// w ww. jav a 2 s . c o m // Workaround for https://github.com/mariotaku/twidere/issues/138 extCacheDir = context.getExternalCacheDir(); } catch (final Exception e) { return new File(context.getCacheDir(), cacheDirName); } if (extCacheDir != null && extCacheDir.isDirectory()) { final File cacheDir = new File(extCacheDir, cacheDirName); if (cacheDir.isDirectory() || cacheDir.mkdirs()) return cacheDir; } return new File(context.getCacheDir(), cacheDirName); }