List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:Main.java
public static void saveSeriObj(Context context, String fileName, Object o) throws Exception { String path = context.getFilesDir() + "/"; File dir = new File(path); dir.mkdirs();/*from ww w.j av a2s . c o m*/ File f = new File(dir, fileName); if (f.exists()) { f.delete(); } FileOutputStream os = new FileOutputStream(f); ObjectOutputStream objectOutputStream = new ObjectOutputStream(os); objectOutputStream.writeObject(o); objectOutputStream.close(); os.close(); }
From source file:Main.java
public synchronized static String id(Context context) { if (ID == null) { File installation = new File(context.getFilesDir(), INSTALLATION); try {/*from www . j a v a2s. c o m*/ if (!installation.exists()) writeInstallationFile(installation); ID = readInstallationFile(installation); } catch (Exception e) { throw new RuntimeException(e); } } return ID; }
From source file:Main.java
public static File getFileDirectory(Context context) { File appCacheDir = null;// w ww . j a va2 s. c om if (appCacheDir == null) { appCacheDir = context.getFilesDir(); } if (appCacheDir == null) { String cacheDirPath = "/data/data/" + context.getPackageName() + "/files/"; appCacheDir = new File(cacheDirPath); } return appCacheDir; }
From source file:Main.java
public static void deleteFromInternalStorage(Context context, final String contains) throws IOException { File file = context.getFilesDir(); FilenameFilter filter = new FilenameFilter() { @Override//w w w . j a v a2 s. c om public boolean accept(File dir, String filename) { return filename.contains(contains); } }; File[] files = file.listFiles(filter); if (files != null) { for (File f : files) { //noinspection ResultOfMethodCallIgnored if (!f.delete()) { throw new IOException("Error while deleting files"); } } } }
From source file:Main.java
@SuppressLint("SdCardPath") public static File getFileDirectory(Context context) { File appCacheDir = null;//from w w w . j av a 2 s . c o m if (appCacheDir == null) { appCacheDir = context.getFilesDir(); } if (appCacheDir == null) { String cacheDirPath = "/data/data/" + context.getPackageName() + "/files/"; appCacheDir = new File(cacheDirPath); } return appCacheDir; }
From source file:Main.java
public static File externalFilesDir(Context c) { File f = c.getExternalFilesDir((String) null); if (f == null || !f.exists()) { f = c.getFilesDir(); }//from w ww . j a v a 2s. co m return f; }
From source file:Main.java
public synchronized static String id(Context context) { if (sID == null) { File installation = new File(context.getFilesDir(), INSTALLATION); try {// ww w . ja v a2 s .c o m if (!installation.exists()) writeInstallationFile(installation); sID = readInstallationFile(installation); } catch (Exception e) { // throw new RuntimeException(e); sID = "1234567890"; } } return sID; }
From source file:Main.java
public static String getPicStorePath(Context ctx) { File file = ctx.getExternalFilesDir(null); if (file == null) { file = ctx.getFilesDir(); }/*from w ww. j av a2s. c om*/ if (!file.exists()) { file.mkdir(); } File imageStoreFile = new File(file.getAbsolutePath() + "/mq"); if (!imageStoreFile.exists()) { imageStoreFile.mkdir(); } return imageStoreFile.getAbsolutePath(); }
From source file:Main.java
public static File getFileDirectory(Context context) { File appCacheDir = null;/*from w ww .j a v a 2 s .c o m*/ if (appCacheDir == null) { appCacheDir = context.getFilesDir(); } if (appCacheDir == null) { String cacheDirPath = "/data/data/" + context.getPackageName() + "/files/"; appCacheDir = new File(cacheDirPath); } filesInCache.add(appCacheDir); return appCacheDir; }
From source file:Main.java
public static void getTelephonyManagerMethods(Context context) { String out;// w ww .j a v a2 s . co m try { File dir = new File(String.valueOf(context.getFilesDir())); // create the file in which we will write the contents String fileName = "telephony.txt"; File file = new File(dir, fileName); FileOutputStream os = new FileOutputStream(file); Class<?> c = Class.forName(GENERIC); Method[] cm = c.getDeclaredMethods(); for (Method m : cm) { out = m.toString() + "\n"; os.write(out.getBytes()); } os.close(); } catch (Exception e) { e.printStackTrace(); } }