List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:Main.java
public static void removeUnusedTiles(Context mContext, final ArrayList<String> usedTiles) { // remove all files are stored in the tile path but are not used File folder = new File(mContext.getFilesDir(), TILE_PATH); File[] unused = folder.listFiles(new FilenameFilter() { @Override// w ww. j a va 2 s. c o m public boolean accept(File dir, String filename) { return !usedTiles.contains(filename); } }); if (unused != null) { for (File f : unused) { f.delete(); } } }
From source file:com.fusionjack.slimota.configs.LinkConfig.java
public static void persistLinks(List<OTALink> links, Context context) { try {//from ww w . j a v a2 s . c om File dir = context.getFilesDir(); File file = new File(dir, FILENAME); if (file.exists()) { file.delete(); } FileOutputStream fos = context.openFileOutput(FILENAME, Context.MODE_PRIVATE); JSONArray jsonLinks = new JSONArray(); for (OTALink link : links) { JSONObject jsonLink = new JSONObject(); jsonLink.put(OTAParser.ID, link.getId()); jsonLink.put(OTAParser.TITLE, link.getTitle()); jsonLink.put(OTAParser.DESCRIPTION, link.getDescription()); jsonLink.put(OTAParser.URL, link.getUrl()); jsonLinks.put(jsonLink); } fos.write(jsonLinks.toString().getBytes()); fos.close(); LinkConfigListener listener = getLinkConfigListener(context); if (listener != null) { listener.onConfigChange(); } } catch (IOException | JSONException e) { OTAUtils.logError(e); } }
From source file:Main.java
public static String getStoragePath(Context context) { String path = null;/* ww w . jav a 2 s . c o m*/ if (hasSDCard(context)) { path = Environment.getExternalStorageDirectory().getAbsolutePath(); } else { path = context.getFilesDir().getAbsolutePath(); } return path; }
From source file:Main.java
public static File getFile(Context context, String filename) { if (context == null || TextUtils.isEmpty(filename)) return null; return new File(context.getFilesDir().getAbsoluteFile() + filename); }
From source file:Main.java
/** * Saves a vcard string to an internal new vcf file. * @param vcard the string to save//from w w w .ja va 2s .c om * @param filename the filename of the vcf * @param context the context used to open streams. */ public static void saveToDisk(String vcard, String filename, Context context) { if (TextUtils.isEmpty(vcard) || TextUtils.isEmpty(filename) || context == null) { return; } String path = context.getFilesDir().getAbsolutePath() + File.separator + "peer_profiles"; File peerProfilesFile = new File(path); if (!peerProfilesFile.exists()) peerProfilesFile.mkdirs(); FileOutputStream outputStream; try { outputStream = new FileOutputStream(path + "/" + filename); outputStream.write(vcard.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static String getDataPath(Context ctx) { String path;//w w w .j av a2 s .c o m // if (isExistSDcard()) // path = Environment.getExternalStorageDirectory().getPath() + "/albumSelect"; // else path = ctx.getFilesDir().getPath(); // if (!path.endsWith("/")) path = path + "/"; return path; }
From source file:com.fusionx.lightirc.util.SharedPreferencesUtils.java
public static String getSharedPreferencesPath(final Context context) { return context.getFilesDir().getAbsolutePath().replace("files", "shared_prefs/"); }
From source file:Main.java
public static String getSendDir(Context context) { File fileDir = context.getExternalFilesDir(null); String dir = null;// w w w . j av a 2 s . c om if (fileDir != null) { dir = fileDir.getAbsolutePath(); } else { dir = context.getFilesDir().getAbsolutePath(); } dir += "/mtc/bgimage/"; fileDir = new File(dir); fileDir.mkdirs(); return dir; }
From source file:com.radadev.xkcd.Comics.java
public static final File getSdDir(Context context) { final String path = context.getFilesDir().getAbsolutePath().replaceFirst("/data", "/sdcard/Android"); File result = new File(path); result.mkdirs();/*from ww w .j ava 2 s . c o m*/ return result; }
From source file:Main.java
public static File getWritableFileDir(Context context) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File file = context.getExternalFilesDir(null); if (file == null) { file = context.getFilesDir(); }// w ww .jav a 2s . c o m return file; } else { return context.getFilesDir(); } }