@Override public void init(Context context) { mApplicationDirectory = context.getExternalFilesDir(null); }
@Override public File getExternalFilesDir(String type) { return mBase.getExternalFilesDir(type); }
private static File getPendingDir(@NonNull Context context) { //File dir = new File(ContextCompat.getDataDir(context), "pending_downloads"); File dir = context.getExternalFilesDir("pending_downloads"); if (dir == null) { // One of the following paths are not accessible ¿unmounted internal memory? // /storage/emulated/0/Android/data/org.schabi.newpipe[.debug]/pending_downloads // /sdcard/Android/data/org.schabi.newpipe[.debug]/pending_downloads Log.w(TAG, "path to pending downloads are not accessible"); } return dir; }
@NonNull @Override public File getFile(@NonNull Context context, @NonNull String fileName) { return new File(context.getExternalFilesDir(null), fileName); } },
public static void ensureExternalCacheDir(Context context) { File file = context.getExternalCacheDir(); if (file == null) { file = new File(context.getExternalFilesDir("").getParentFile(), "cache"); } if (file != null) { file.mkdirs(); } }
RecordingSession(Context ctxt, RecordingConfig config, MediaProjection projection) { this.ctxt=ctxt.getApplicationContext(); this.config=config; this.projection=projection; this.beeper=new ToneGenerator( AudioManager.STREAM_NOTIFICATION, 100); output=new File(ctxt.getExternalFilesDir(null), "andcorder.mp4"); output.getParentFile().mkdirs(); }
@Override public Fragment getItem(int position) { File fileToEdit; switch(position) { case TAB_INTERNAL: fileToEdit=new File(ctxt.getFilesDir(), FILENAME); break; case TAB_EXTERNAL: fileToEdit=new File(ctxt.getExternalFilesDir(null), FILENAME); break; default: fileToEdit= new File(Environment. getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), FILENAME); break; } return(EditorFragment.newInstance(fileToEdit)); }
@Override public Fragment getItem(int position) { File fileToEdit; switch(position) { case TAB_INTERNAL: fileToEdit=new File(ctxt.getFilesDir(), FILENAME); break; case TAB_EXTERNAL: fileToEdit=new File(ctxt.getExternalFilesDir(null), FILENAME); break; default: fileToEdit= new File(Environment. getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), FILENAME); break; } return(EditorFragment.newInstance(fileToEdit)); }
@Override public Fragment getItem(int position) { File fileToEdit; switch(position) { case TAB_INTERNAL: fileToEdit=new File(ctxt.getFilesDir(), FILENAME); break; case TAB_EXTERNAL: fileToEdit=new File(ctxt.getExternalFilesDir(null), FILENAME); break; default: fileToEdit= new File(Environment. getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), FILENAME); break; } return(EditorFragment.newInstance(fileToEdit)); }
private static String extractDatabase(Context context) { try { File external = context.getExternalFilesDir(null); File data = Environment.getDataDirectory(); if (external != null && external.canWrite()) { String dataDBPath = "data/" + context.getPackageName() + "/databases/chuck.db"; String extractDBPath = "chuckdb.temp"; File dataDB = new File(data, dataDBPath); File extractDB = new File(external, extractDBPath); if (dataDB.exists()) { FileChannel in = new FileInputStream(dataDB).getChannel(); FileChannel out = new FileOutputStream(extractDB).getChannel(); out.transferFrom(in, 0, in.size()); in.close(); out.close(); return extractDB.getAbsolutePath(); } } } catch (Exception e) { e.printStackTrace(); } return null; }
logger.log(Level.FINE, "ExternalStorageState: {0}", state); if (state.equals(Environment.MEDIA_MOUNTED)) { storageFolder = view.getContext().getExternalFilesDir(null); storageFolders.put(type, storageFolder);
/** * 各种类型的文件的专用的保存路径,以“/”结尾 * * @return 诸如:/mnt/sdcard/Android/data/[package]/files/[type]/ */ public static String getExternalPrivatePath(Context context, String type) { File file = null; if (externalMounted()) { file = context.getExternalFilesDir(type); } //高频触发java.lang.NullPointerException,是SD卡不可用或暂时繁忙么? String path = ""; if (file != null) { path = FileUtils.separator(file.getAbsolutePath()); } LogUtils.verbose("external storage private path: " + path); return path; }
@Test public void getExternalFilesDir_shouldCreateDirectory() throws Exception { assertThat(context.getExternalFilesDir(null).exists()).isTrue(); }
@Test public void getExternalFilesDir_shouldCreateNamedDirectory() throws Exception { File f = context.getExternalFilesDir("__test__"); assertThat(f.exists()).isTrue(); assertThat(f.getAbsolutePath()).endsWith("__test__"); }
String path = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/"; dbFile = new File(path + dbName); boolean result = dbFile.delete();
@Test @Config(minSdk = LOLLIPOP) public void startStopTracingSamplingShouldWriteFile() { Debug.startMethodTracingSampling(TRACE_FILENAME, 100, 100); Debug.stopMethodTracing(); assertThat(new File(context.getExternalFilesDir(null), TRACE_FILENAME).exists()).isTrue(); }
@Test public void startStopTracingShouldWriteFile() { Debug.startMethodTracing(TRACE_FILENAME); Debug.stopMethodTracing(); assertThat(new File(context.getExternalFilesDir(null), TRACE_FILENAME).exists()).isTrue(); }
String dbName = litePalAttr.getDbName(); if ("external".equalsIgnoreCase(litePalAttr.getStorage())) { dbName = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/" + dbName; } else if (!"internal".equalsIgnoreCase(litePalAttr.getStorage()) && !TextUtils.isEmpty(litePalAttr.getStorage())) {
/** * Create diary dir file manager */ public FileManager(Context context, long topicId, long diaryId) { this.mContext = context; this.fileDir = mContext.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + topicId + "/" + diaryId + "/"); }
/** * @param context 上下文 * @param customPath 自定义路径 * @return 内存卡文件目录 */ public static String getExternalFileDir(Context context, String customPath) { String path = context.getExternalFilesDir("") + formatPath(customPath); mkdir(path); return path; }