List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:com.noshufou.android.su.util.Util.java
public static boolean writeOptionsFile(Context context) { File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored"); storedDir.mkdirs();/* w w w. j a v a2 s.c o m*/ File optFile = new File(storedDir.getAbsolutePath() + File.separator + "options"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String ownerMode = prefs.getString(Preferences.USER_MODE, "owner_only"); try { OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(optFile.getAbsolutePath())); out.write(ownerMode); out.write("\n"); out.flush(); out.close(); } catch (FileNotFoundException e) { Log.w(TAG, "Options file not written", e); return false; } catch (IOException e) { Log.w(TAG, "Options file not written", e); return false; } return true; }
From source file:com.noshufou.android.su.util.Util.java
private static File getStoreFile(Context context, int uid, int execUid) { File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored"); storedDir.mkdirs();//from ww w . j a v a 2 s .co m String fileName = uid + "-" + execUid; return new File(storedDir, fileName); }
From source file:com.noshufou.android.su.util.Util.java
public static final Boolean isSuid(Context context, String filename) { try {/*from ww w . j a v a 2s . c o m*/ Process p = Runtime.getRuntime().exec(context.getFilesDir() + "/test -u " + filename); p.waitFor(); if (p.exitValue() == 0) { Log.d(TAG, filename + " is set-user-ID"); return true; } } catch (Exception e) { e.printStackTrace(); } Log.d(TAG, filename + " is not set-user-ID"); return false; }
From source file:com.duy.pascal.ui.file.FileManager.java
@Nullable public static File getSrcPath(Context context) { final String dirName = "PascalCompiler"; int i = 0;/*from ww w .j a v a2s . c o m*/ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { i = ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE); if (i == PackageManager.PERMISSION_GRANTED) { File file = new File(Environment.getExternalStorageDirectory(), dirName); if (!file.exists()) { file.mkdirs(); } return file; } } else { return new File(context.getFilesDir(), dirName); } return null; }
From source file:fr.simon.marquis.preferencesmanager.util.Utils.java
public static boolean savePreferences(PreferenceFile preferenceFile, String file, String packageName, Context ctx) { Log.d(TAG, String.format("savePreferences(%s, %s)", file, packageName)); if (preferenceFile == null) { Log.e(TAG, "Error preferenceFile is null"); return false; }/*from ww w.j a v a2 s . c om*/ if (!preferenceFile.isValid()) { Log.e(TAG, "Error preferenceFile is not valid"); return false; } String preferences = preferenceFile.toXml(); if (TextUtils.isEmpty(preferences)) { Log.e(TAG, "Error preferences is empty"); return false; } File tmpFile = new File(ctx.getFilesDir(), TMP_FILE); try { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( ctx.openFileOutput(TMP_FILE, Context.MODE_PRIVATE)); outputStreamWriter.write(preferences); outputStreamWriter.close(); } catch (IOException e) { Log.e(TAG, "Error writing temporary file", e); return false; } if (!RootTools.copyFile(tmpFile.getAbsolutePath(), file, true, false)) { Log.e(TAG, "Error copyFile from temporary file"); return false; } if (!fixUserAndGroupId(ctx, file, packageName)) { Log.e(TAG, "Error fixUserAndGroupId"); return false; } if (!tmpFile.delete()) { Log.e(TAG, "Error deleting temporary file"); } RootTools.killProcess(packageName); Log.d(TAG, "Preferences correctly updated"); return true; }
From source file:Main.java
public static boolean isInstalledOnSdCard(Context context) { // check for API level 8 and higher if (isCompatible(8)) { PackageManager pm = context.getPackageManager(); try {/*from w ww. ja v a2 s .co m*/ PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); ApplicationInfo ai = pi.applicationInfo; return (ai.flags & 0x00040000 /* * ApplicationInfo. * FLAG_EXTERNAL_STORAGE */) == 0x00040000 /* * ApplicationInfo. * FLAG_EXTERNAL_STORAGE */; } catch (NameNotFoundException e) { // ignore } } // check for API level 7 - check files dir try { String filesDir = context.getFilesDir().getAbsolutePath(); if (filesDir.startsWith("/data/")) { return false; } else if (filesDir.contains(Environment.getExternalStorageDirectory().getPath())) { return true; } } catch (Throwable e) { // ignore } return false; }
From source file:csic.ceab.movelab.beepath.Util.java
/** * Saves a byte array to the internal storage directory. * /* w w w. java 2 s . c o m*/ * @param context * The application context. * @param filename * The file name to use. * @param bytes * The byte array to be saved. */ public static void saveJSON(Context context, String dir, String fileprefix, String inputString) { // String TAG = "Util.saveFile"; FileOutputStream fos = null; FileLock lock = null; try { byte[] bytes = inputString.getBytes("UTF-8"); File directory = new File(context.getFilesDir().getAbsolutePath(), dir); directory.mkdirs(); File target = new File(directory, fileprefix + System.currentTimeMillis() + ".txt"); fos = new FileOutputStream(target); lock = fos.getChannel().lock(); fos.write(bytes); } catch (IOException e) { // logging exception but doing nothing // Log.e(TAG, "Exception " + e); } finally { if (lock != null) { try { lock.release(); } catch (Exception e) { } } if (fos != null) { try { fos.close(); } catch (IOException e) { // logging exception but doing nothing // Log.e(TAG, "Exception " + e); } } } }
From source file:org.qeo.android.service.QeoService.java
/** * Get the qeo storage directory.// w w w .j a v a2 s . co m * * @param ctx The android context. * @return The path. */ public static String getStorageDir(Context ctx) { if (QeoDefaults.getQeoStorageDir() == null) { return ctx.getFilesDir().getAbsolutePath(); } else { return QeoDefaults.getQeoStorageDir(); } }
From source file:com.grarak.kerneladiutor.utils.database.CommandDB.java
/** * Read the JSON file from cache//from www . j a v a 2s . co m * * @param context needed to get the cache directory */ public CommandDB(Context context) { super(context.getFilesDir() + "/commands.json", 1); }
From source file:com.grarak.kerneladiutor.database.Settings.java
/** * Read the JSON file from cache// ww w. j a v a 2s.co m * * @param context needed to get the cache directory */ public Settings(Context context) { super(context.getFilesDir() + "/settings.json", 1); if (Utils.existFile(context.getFilesDir() + "/commands.json", false)) { new File(context.getFilesDir() + "/commands.json").delete(); } }