@RequiresApi(KITKAT) @Override public File[] getExternalFilesDirs(String type) { return mBase.getExternalFilesDirs(type); }
Os.symlink(moviesDir.getAbsolutePath(), new File(storageDir, "movies").getAbsolutePath()); final File[] dirs = context.getExternalFilesDirs(null); if (dirs != null && dirs.length > 1) { for (int i = 1; i < dirs.length; i++) {
@Ignore @Test @Config(minSdk = KITKAT) public void getExternalFilesDirs() throws Exception { ShadowEnvironment.addExternalDir("external_dir_1"); ShadowEnvironment.addExternalDir("external_dir_2"); File[] externalFilesDirs = ApplicationProvider.getApplicationContext() .getExternalFilesDirs(Environment.DIRECTORY_MOVIES); assertThat(externalFilesDirs).isNotEmpty(); assertThat(externalFilesDirs[0].getCanonicalPath()).contains("external_dir_1"); assertThat(externalFilesDirs[1].getCanonicalPath()).contains("external_dir_2"); // TODO(jongerrish): This fails because ShadowContext overwrites getExternalFilesDir. // assertThat(RuntimeEnvironment.application.getExternalFilesDir(Environment.DIRECTORY_MOVIES) // .getCanonicalPath()).contains("external_dir_1"); }
@RequiresApi(KITKAT) @Override public File[] getExternalFilesDirs(String type) { return mBase.getExternalFilesDirs(type); }
externalFilesDir.addAll(Arrays.asList(context.getExternalFilesDirs(null))); externalFilesDir.remove(context.getExternalFilesDir(null)); if (externalFilesDir.size() == 0) {
@Override public File[] getExternalFilesDirs(String type) { return hostContext.getExternalFilesDirs(type); }
@Override public File[] getExternalFilesDirs(String type) { return hostContext.getExternalFilesDirs(type); }
public static File[] getExternalFilesDirs(Context context, String type) { return context.getExternalFilesDirs(type); }
@TargetApi(Build.VERSION_CODES.KITKAT) @Override public PortableFile[] getExternalFilesDirs(Context context) { File[] externalFilesDirs = context.getExternalFilesDirs(null); PortableFile[] result = new PortableFileImpl[externalFilesDirs.length]; for (int i = 0; i < externalFilesDirs.length; i++) { result[i] = PortableFileImpl.make(externalFilesDirs[i]); } return result; }
public static Collection<File> getStorages(Context context) { HashSet<File> dirsToScan = new HashSet<>(); dirsToScan.add(Environment.getExternalStorageDirectory()); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // hack. Don't know if it work well on other devices! String userPathToRemove = "Android/data/souch.smp/files"; for (File dir : context.getExternalFilesDirs(null)) { if (dir.getAbsolutePath().endsWith(userPathToRemove)) { dirsToScan.add(dir.getParentFile().getParentFile().getParentFile().getParentFile()); } } } for (File dir: dirsToScan) { Log.d("Settings", "userDir: " + dir.getAbsolutePath()); } return dirsToScan; }
public static File[] getRemovableStorageRoots(Context context) { File[] roots = context.getExternalFilesDirs("external"); ArrayList<File> rootsArrayList = new ArrayList<>(); for (int i = 0; i < roots.length; i++) { if (roots[i] != null) { String path = roots[i].getPath(); int index = path.lastIndexOf("/Android/data/"); if (index > 0) { path = path.substring(0, index); if (!path.equals(Environment.getExternalStorageDirectory().getPath())) { rootsArrayList.add(new File(path)); } } } } roots = new File[rootsArrayList.size()]; rootsArrayList.toArray(roots); return roots; }
File[] ff = ctx.getExternalFilesDirs(null); if (ff == null) return null;
File fileList2[] = _context.getExternalFilesDirs(Environment.DIRECTORY_DOWNLOADS);
@TargetApi(Build.VERSION_CODES.KITKAT) public static File getBestAvailableFilesRoot(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // In KitKat we can query multiple devices. // TODO: optimize for stability instead of picking first one File[] roots = context.getExternalFilesDirs(null); if (roots != null) { for (File root : roots) { if (root == null) { continue; } if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(root))) { return root; } } } } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // Pre-KitKat, only one external storage device was addressable return context.getExternalFilesDir(null); } // Worst case, resort to internal storage return context.getFilesDir(); }
private static File findCollectionDirectory(Context context) { String subDirectory = "Collection"; File[] storage = context.getExternalFilesDirs(subDirectory); for (File file : storage) { if (file != null) { String state = EnvironmentCompat.getStorageState(file); if (Environment.MEDIA_MOUNTED.equals(state)) { LogHelper.v(LOG_TAG, "External storage: " + file.toString()); return file; } } } return null; }
public static ArrayList<String> getStorageList(Context context) { ArrayList<String> storages = new ArrayList<>(); storages.add(Environment.getExternalStorageDirectory().getAbsolutePath()); String altPath = altExtStoragePath(); if (TextUtils.isEmpty(altPath)) storages.add(altPath); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { /* * First volume returned by getExternalFilesDirs is always primary storage, * or emulated. Further entries, if they exist, will be secondary or external SD, * see http://www.doubleencore.com/2014/03/android-external-storage/ */ File[] filesDirs = context.getExternalFilesDirs(null); if (filesDirs != null) { /* Skip primary storage */ for (int i = 1; i < filesDirs.length; i++) { if (filesDirs[i] != null) { if (filesDirs[i].exists()) storages.add(filesDirs[i].getAbsolutePath()); else Log.w(TAG, "Unexpected external storage: " + filesDirs[i].getAbsolutePath()); } } } } return storages; }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { files = context.getExternalFilesDirs(null); } else { files = ContextCompat.getExternalFilesDirs(context, null);
File[] files = context.getExternalFilesDirs(null); for (File file : files) { String applicationSpecificAbsolutePath = file.getAbsolutePath();
final File[] dirs = context.getExternalFilesDirs(null); final int n = dirs != null ? dirs.length : 0; final StringBuilder sb = new StringBuilder();