List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:fr.simon.marquis.preferencesmanager.util.Utils.java
public static boolean backupFile(String backup, String fileName, Context ctx) { Log.d(TAG, String.format("backupFile(%s, %s)", backup, fileName)); File destination = new File(ctx.getFilesDir(), backup); if (!RootTools.copyFile(fileName, destination.getAbsolutePath(), true, true)) { Log.e(TAG, "Error copyFile"); return false; }/*from w ww.j av a 2 s . co m*/ Log.d(TAG, String.format("backupFile --> " + destination)); return true; }
From source file:it.feio.android.omninotes.utils.StorageManager.java
public static File getSharedPreferencesFile(Context mContext) { File appData = mContext.getFilesDir().getParentFile(); String packageName = mContext.getApplicationContext().getPackageName(); File prefsPath = new File(appData + System.getProperty("file.separator") + "shared_prefs" + System.getProperty("file.separator") + packageName + "_preferences.xml"); return prefsPath; }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public final static File getConfigDir(Context context, SharedPreferences sharedPreferences) { final File configDir; if (getUseInternalStorage(sharedPreferences)) { configDir = new File(context.getFilesDir(), "config.d"); if (!configDir.exists()) configDir.mkdir();//from w w w . j ava 2s . co m } else { configDir = getExternalStorageAsFile(sharedPreferences); } return configDir; }
From source file:com.platform.middlewares.plugins.CameraPlugin.java
private static String writeToFile(Context context, Bitmap img) { String name = null;/*from w ww . java 2 s .co m*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); try { img.compress(Bitmap.CompressFormat.JPEG, 50, out); name = CryptoHelper.base58ofSha256(out.toByteArray()); File storageDir = new File(context.getFilesDir().getAbsolutePath() + "/pictures/"); File image = new File(storageDir, name + ".jpeg"); FileUtils.writeByteArrayToFile(image, out.toByteArray()); return name; // PNG is a lossless format, the compression factor (100) is ignored } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:io.nuclei.splice.internal.FileManager.java
private static File getBaseFile(Context context, int type) throws IOException { File base = null;/*from w w w . j a va 2s . c o m*/ if (type == TYPE_EXTERNAL_FILE && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) base = new File(context.getExternalFilesDir(null), DIR); else if (type == TYPE_CACHE_FILE) base = new File(context.getCacheDir(), DIR); else if (type == TYPE_LOCAL_FILE) base = new File(context.getFilesDir(), DIR); if (base == null) throw new IOException("Couldn't access directory type: " + type); if (!base.exists() && !base.mkdirs()) throw new IOException("Couldn't create directory: " + base); return base; }
From source file:com.cw.litenote.config.Config.java
public static void clearSharedPreferences(Context ctx) { // String path = ctx.getFilesDir().getParent() + "/shared_prefs/"; // if(Util.isUriExisted(path, ctx)) {/*from w w w. j ava2s.c om*/ File dir = new File(ctx.getFilesDir().getParent() + "/shared_prefs/"); String[] children = dir.list(); for (int i = 0; i < children.length; i++) { System.out.println("1: " + children[i]); // clear each of the preferences ctx.getSharedPreferences(children[i].replace(".xml", ""), Context.MODE_PRIVATE).edit().clear() .commit(); } // Make sure it has enough time to save all the committed changes try { Thread.sleep(1000); } catch (InterruptedException e) { } for (int i = 0; i < children.length; i++) { System.out.println("2: " + children[i]); // delete the files new File(dir, children[i]).delete(); } } }
From source file:at.jclehner.rxdroid.Backup.java
public static List<File> getBackupDirectories(Context context) { final List<File> dirs = new ArrayList<>(); dirs.add(context.getFilesDir()); for (StorageHelper.PathInfo si : StorageHelper.getDirectories(context)) dirs.add(new File(si.path, DIRECTORY_NAME)); return dirs;//from ww w. j a v a2s .co m }
From source file:fr.simon.marquis.preferencesmanager.util.Utils.java
public static boolean restoreFile(Context ctx, String backup, String fileName, String packageName) { Log.d(TAG, String.format("restoreFile(%s, %s, %s)", backup, fileName, packageName)); File backupFile = new File(ctx.getFilesDir(), backup); if (!RootTools.copyFile(backupFile.getAbsolutePath(), fileName, true, true)) { Log.e(TAG, "Error copyFile"); return false; }/*from w ww .j ava 2s . c o m*/ if (!fixUserAndGroupId(ctx, fileName, packageName)) { Log.e(TAG, "Error fixUserAndGroupId"); return false; } if (!RootTools.killProcess(packageName)) { Log.e(TAG, "Error killProcess"); return false; } Log.d(TAG, String.format("restoreFile --> " + fileName)); return true; }
From source file:com.brewcrewfoo.performance.util.Helpers.java
public static String readCPU(Context context, int i) { Helpers.get_assetsScript("utils", context, "", ""); new CMDProcessor().sh.runWaitFor("busybox chmod 750 " + context.getFilesDir() + "/utils"); CMDProcessor.CommandResult cr = new CMDProcessor().su .runWaitFor(context.getFilesDir() + "/utils -getcpu " + i); if (cr.success()) return cr.stdout; else//www.ja v a2s . c o m return null; }
From source file:com.owncloud.android.network.OwnCloudClientUtils.java
/** * Returns the local store of reliable server certificates, explicitly accepted by the user. * /*from w w w.j a v a 2 s. com*/ * Returns a KeyStore instance with empty content if the local store was never created. * * Loads the store from the storage environment if needed. * * @param context Android context where the operation is being performed. * @return KeyStore instance with explicitly-accepted server certificates. * @throws KeyStoreException When the KeyStore instance could not be created. * @throws IOException When an existing local trust store could not be loaded. * @throws NoSuchAlgorithmException When the existing local trust store was saved with an unsupported algorithm. * @throws CertificateException When an exception occurred while loading the certificates from the local trust store. */ private static KeyStore getKnownServersStore(Context context) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { if (mKnownServersStore == null) { //mKnownServersStore = KeyStore.getInstance("BKS"); mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType()); File localTrustStoreFile = new File(context.getFilesDir(), LOCAL_TRUSTSTORE_FILENAME); Log_OC.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath()); if (localTrustStoreFile.exists()) { InputStream in = new FileInputStream(localTrustStoreFile); try { mKnownServersStore.load(in, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); } finally { in.close(); } } else { mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); // necessary to initialize an empty KeyStore instance } } return mKnownServersStore; }