List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:at.ac.uniklu.mobile.sportal.Studentportal.java
public static void clearCaches(Context applicationContext) { getSportalClient().clearCache();/* ww w .j a v a 2s . com*/ getStudentPortalDB().mutingPeriods_clear(); // delete cached profile pictures File privateFilesDir = applicationContext.getFilesDir(); for (File privateFile : privateFilesDir.listFiles()) { privateFile.delete(); } // delete application cache (webview etc...) Utils.clearAppCache(applicationContext); }
From source file:Main.java
public static File getFile(Context context, Uri uri, boolean forceCreation) { if (!forceCreation && "file".equalsIgnoreCase(uri.getScheme())) { return new File(uri.getPath()); }// w w w. j ava 2s . c o m File file = null; try { File root = context.getFilesDir(); if (root == null) { throw new Exception("data dir not found"); } file = new File(root, getFilename(context, uri)); file.delete(); InputStream is = context.getContentResolver().openInputStream(uri); OutputStream os = new FileOutputStream(file); byte[] buf = new byte[1024]; int cnt = is.read(buf); while (cnt > 0) { os.write(buf, 0, cnt); cnt = is.read(buf); } os.close(); is.close(); file.deleteOnExit(); } catch (Exception e) { Log.e("OpenFile", e.getMessage(), e); } return file; }
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 w w w . j av a2 s . c o m return new File(context.getFilesDir(), "info.log"); }
From source file:io.github.data4all.util.upload.GpxTrackUtil.java
/** * Method for reading a track from memory. Return a string representation of * a saved track.//from ww w . jav a 2 s . c om * * @param context * the context * @param trackXml * the xml file of the gpx track * @param fileName * the filename of the gpx track * @return a file object containing the gpx tracks */ private static File createGpxFile(Context context, String trackXml, String fileName) { final File file = new File(context.getFilesDir(), fileName); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); writer.write(trackXml); writer.close(); } catch (IOException e) { Log.e(GpxTrackUtil.class.getSimpleName(), "IOException: ", e); } return file; }
From source file:uk.ac.horizon.aestheticodes.controllers.ExperienceListUpdater.java
public static void save(Context context, ExperienceListController experiences) { try {/*from www . ja v a2 s.c o m*/ final File experienceFile = new File(context.getFilesDir(), "experiences.json"); final FileWriter writer = new FileWriter(experienceFile); final Collection<Experience> saveExperiences = new ArrayList<>(); for (Experience experience : experiences.get()) { if (experience.getOp() != Experience.Operation.temp) { saveExperiences.add(experience); } } Gson gson = ExperienceParser.createParser(); gson.toJson(saveExperiences, writer); writer.flush(); writer.close(); } catch (Exception e) { Log.e("", e.getMessage(), e); } }
From source file:com.jsonstore.util.JSONStoreUtil.java
public static final File getNoBackupFilesDir(Context ctx) { if (android.os.Build.VERSION.SDK_INT <= LOLLIPOP_MR1) return ctx.getFilesDir(); else//from w ww .jav a 2 s .c o m return ctx.getNoBackupFilesDir(); }
From source file:Main.java
public static File getSDDir(Context context) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // We can read and write the media return context.getExternalFilesDir(null); } else {/*from w ww.j a va 2 s.c o m*/ // Load another directory, probably local memory return context.getFilesDir(); } }
From source file:org.opensilk.music.AppPreferences.java
public static String readAutoShuffleDirectory(Context context) { try {//from w w w. j ava 2s . co m File f = new File(context.getFilesDir(), AUTO_SHUFFLE_FOLDER); return FileUtils.readLines(f).get(0); } catch (Exception e) { return null; } }
From source file:com.dajodi.scandic.Util.java
public static void writeMemberInfo(Context context, MemberInfo memberInfo) throws IOException { PersistedData data = new PersistedData(); data.setMemberInfo(memberInfo);/*from w w w. j a v a 2 s. com*/ File f = context.getFilesDir(); Writer writer = new BufferedWriter(new FileWriter(new File(f, JSON_FILENAME))); try { new JSONSerializer().deepSerialize(data, writer); writer.flush(); } finally { writer.close(); } }
From source file:org.opensilk.music.AppPreferences.java
public static boolean writeAutoShuffleDirectory(Context context, String directory) { try {//from w w w . j av a 2s . co m File f = new File(context.getFilesDir(), AUTO_SHUFFLE_FOLDER); FileUtils.writeLines(f, Collections.singleton(directory)); return true; } catch (IOException e) { return false; } }