List of usage examples for android.content Context getExternalFilesDir
@Nullable public abstract File getExternalFilesDir(@Nullable String type);
From source file:Main.java
/** * Get a writeable cache directory for saving cache files * * @param context/*from ww w . j a v a 2s . c om*/ * @return file directory or null */ public static File getApplicationCacheDirectory(Context context) { File directory = context.getFilesDir(); String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { File externalDirectory = context.getExternalFilesDir(null); if (externalDirectory != null) { directory = externalDirectory; } } File cacheDirectory = new File(directory, CACHE_DIRECTORY); if (!cacheDirectory.exists()) { cacheDirectory.mkdir(); } return cacheDirectory; }
From source file:com.zenome.bundlebus.Util.java
public static String getFolderWithStr(Context aContext, String aAppKey, String aFolderName) { return aContext.getExternalFilesDir(null) + File.separator + aAppKey + File.separator + aFolderName + File.separator;// www .j a va2 s. c o m }
From source file:nuclei.logs.Logs.java
protected static File newLogFile() { Context context = ContextHandle.getApplicationHandle().get(); if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { return new File(context.getExternalFilesDir(null), "info.log"); }//from www.ja va 2 s . co m return new File(context.getFilesDir(), "info.log"); }
From source file:Main.java
public static File getOutputMediaFile(Context context, String mediaName) { File mediaStorageDir = null;/*from w w w .j a v a2s .c o m*/ try { // mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), ImgFolderName); mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), ImgFolderName); } catch (Exception e) { e.printStackTrace(); } if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } File mediaFile = new File(mediaStorageDir.getPath() + File.separator + mediaName); return mediaFile; }
From source file:org.proninyaroslav.libretorrent.core.utils.TorrentUtils.java
public static void saveSession(Context context, byte[] data) throws Exception { String dataDir = context.getExternalFilesDir(null).getAbsolutePath(); File sessionFile = new File(dataDir, TorrentStorage.Model.DATA_TORRENT_SESSION_FILE); FileUtils.writeByteArrayToFile(sessionFile, data); }
From source file:hochschuledarmstadt.photostream_tools.ImageCacher.java
static void deleteAllCachedImages(Context context) { File file = context.getFilesDir(); internalDeleteAllCachedImages(file); if (isExternalStorageAccessible()) { File pictureDirectory = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); internalDeleteAllCachedImages(pictureDirectory); }//from ww w . j av a2 s . co m }
From source file:org.proninyaroslav.libretorrent.core.utils.TorrentUtils.java
@Nullable public static String findSessionFile(Context context) { if (FileIOUtils.isStorageReadable()) { String dataDir = context.getExternalFilesDir(null).getAbsolutePath(); File session = new File(dataDir, TorrentStorage.Model.DATA_TORRENT_SESSION_FILE); if (session.exists()) { return session.getAbsolutePath(); }//w ww . j a v a 2 s. c o m } return null; }
From source file:org.proninyaroslav.libretorrent.core.utils.TorrentUtils.java
@Nullable public static String findTorrentDataDir(Context context, String id) { if (FileIOUtils.isStorageReadable()) { File dataDir = new File(context.getExternalFilesDir(null), id); if (dataDir.exists()) { return dataDir.getAbsolutePath(); }//w w w . j a va 2 s . c o m } return null; }
From source file:org.proninyaroslav.libretorrent.core.utils.TorrentUtils.java
public static boolean torrentDataExists(Context context, String id) { if (FileIOUtils.isStorageReadable()) { File dataDir = new File(context.getExternalFilesDir(null), id); if (dataDir.exists()) { File torrentFile = new File(dataDir, TorrentStorage.Model.DATA_TORRENT_FILE_NAME); if (torrentFile.exists()) { return true; }//from ww w . ja v a2s. co m } } return false; }
From source file:org.proninyaroslav.libretorrent.core.utils.TorrentUtils.java
@Nullable public static String makeTorrentDataDir(Context context, String name) { if (!FileIOUtils.isStorageWritable()) { return null; }/*ww w . jav a2 s .c om*/ String dataDir = context.getExternalFilesDir(null).getAbsolutePath(); File newDir = new File(dataDir, name); return (newDir.mkdir()) ? newDir.getAbsolutePath() : null; }