List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:com.domowe.apki.lista2.Utils.java
public static File getFileFromName(Context context, String name) { //return new File(Environment.getExternalStorageDirectory(),name); return new File(context.getFilesDir(), name); }
From source file:Main.java
public static String getSavePath(Context context) { boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (hasSDCard) { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); }/*from ww w . jav a 2s. com*/ return context.getFilesDir().toString(); }
From source file:Main.java
public static void setFBImage(final String fbid, final Context context, final ImageView v) { new AsyncTask<String, Void, Bitmap>() { @Override//from w ww. ja v a2 s .com protected Bitmap doInBackground(String... strings) { File img = new File(context.getFilesDir() + "/profile.jpg"); Bitmap bmp = null; if (img.exists()) { try { bmp = BitmapFactory.decodeFile(img.getAbsolutePath()); } catch (Exception E) { E.printStackTrace(); } } else { try { URL img_url = new URL("https://graph.facebook.com/" + String.valueOf(fbid) + "/picture?type=large&redirect=true&width=400&height=400"); bmp = BitmapFactory.decodeStream(img_url.openConnection().getInputStream()); FileOutputStream fOut = new FileOutputStream(img); bmp.compress(Bitmap.CompressFormat.JPEG, 90, fOut); fOut.flush(); fOut.close(); } catch (Exception E) { E.printStackTrace(); } } return bmp; } @Override protected void onPostExecute(Bitmap img) { if (img != null) { v.setImageBitmap(img); } } }.execute(); }
From source file:com.google.codelab.networkmanager.CodelabUtil.java
/** * Overwrite Tasks in file with those given here. *//*from w w w . j a v a 2 s.co m*/ private static void saveTaskItemsToFile(Context context, List<TaskItem> taskItems) { String taskStr = taskItemsToString(taskItems); File file = new File(context.getFilesDir(), FILE_NAME); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); return; } } try { FileOutputStream fileOutputStream = new FileOutputStream(file); IOUtils.write(taskStr, fileOutputStream); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static File getFileName(String dirPath, String fileName, Context context) { File mLogDir;// www . j a va2 s . c om if (isSDCardAvailable()) { mLogDir = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + dirPath); } else { mLogDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + dirPath); } if (!mLogDir.exists()) { mLogDir.mkdirs(); } return new File(mLogDir.getAbsolutePath() + File.separator + fileName); }
From source file:org.dolphinemu.dolphinemu.utils.DirectoryInitialization.java
private static void initializeInternalStorage(Context context) { File sysDirectory = new File(context.getFilesDir(), "Sys"); internalPath = sysDirectory.getAbsolutePath(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String revision = NativeLibrary.GetGitRevision(); if (!preferences.getString("sysDirectoryVersion", "").equals(revision)) { // There is no extracted Sys directory, or there is a Sys directory from another // version of Dolphin that might contain outdated files. Let's (re-)extract Sys. deleteDirectoryRecursively(sysDirectory); copyAssetFolder("Sys", sysDirectory, true, context); SharedPreferences.Editor editor = preferences.edit(); editor.putString("sysDirectoryVersion", revision); editor.apply();//from w w w . ja va 2 s. c o m } // Let the native code know where the Sys directory is. SetSysDirectory(sysDirectory.getPath()); }
From source file:Main.java
public static void copyDatabase2FileDir(Context context, String dbName) { InputStream stream = null;/*from w w w.j ava2 s . c o m*/ BufferedOutputStream outputStream = null; try { stream = context.getAssets().open(dbName); File file = new File(context.getFilesDir(), dbName); outputStream = new BufferedOutputStream(new FileOutputStream(file)); int len = 0; byte[] buf = new byte[1024]; while ((len = stream.read(buf)) != -1) { outputStream.write(buf, 0, len); outputStream.flush(); } } catch (IOException e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:net.naonedbus.utils.InfoDialogUtils.java
/** * Afficher une dialog avec un message, uniquement si elle n'a pas dj t * affiche//from w ww .j a v a 2 s . c o m * * @param context * @param messageId */ public static void showIfNecessary(final Context context, final int messageId) { final File dataFile = new File(context.getFilesDir(), MESSAGE_FOLDER + File.separator + messageId); createDir(context); if (!dataFile.exists()) { show(context, messageId); try { dataFile.createNewFile(); } catch (final IOException e) { BugSenseHandler.sendExceptionMessage("Erreur lors de la cration du marqueur", null, e); } } }
From source file:net.naonedbus.utils.InfoDialogUtils.java
/** * Indique si un message n'a pas dj t affich, et le marque comme * affich./* w ww . j av a 2s . c o m*/ * * @param context * @param messageId * L'id du message en question. * @return <code>true</code> si le message n'a pas encore t affich, * <code>false</code> s'il l'a dj t. */ public static boolean isNotAlreadyShown(final Context context, final int messageId) { final File dataFile = new File(context.getFilesDir(), MESSAGE_FOLDER + File.separator + messageId); boolean result = true; createDir(context); if (!dataFile.exists()) { try { dataFile.createNewFile(); } catch (final IOException e) { BugSenseHandler.sendExceptionMessage("Erreur lors de la cration du marqueur", null, e); } } else { result = false; } return result; }
From source file:Main.java
public static String getFile(@NonNull Context context) { File savedir = null;//from w w w .j a va 2 s. c om if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { savedir = context.getExternalFilesDir(null); } if (savedir == null) { savedir = context.getFilesDir(); } if (!savedir.exists()) { savedir.mkdirs(); } return savedir.getAbsolutePath(); }