本文整理了Java中android.content.Context.getExternalFilesDirs()
方法的一些代码示例,展示了Context.getExternalFilesDirs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getExternalFilesDirs()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getExternalFilesDirs
暂无
代码示例来源:origin: oasisfeng/condom
@RequiresApi(KITKAT) @Override public File[] getExternalFilesDirs(String type) {
return mBase.getExternalFilesDirs(type);
}
代码示例来源:origin: termux/termux-app
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++) {
代码示例来源:origin: robolectric/robolectric
@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");
}
代码示例来源:origin: Trumeet/MiPushFramework
@RequiresApi(KITKAT) @Override public File[] getExternalFilesDirs(String type) {
return mBase.getExternalFilesDirs(type);
}
代码示例来源:origin: syncthing/syncthing-android
externalFilesDir.addAll(Arrays.asList(context.getExternalFilesDirs(null)));
externalFilesDir.remove(context.getExternalFilesDir(null));
if (externalFilesDir.size() == 0) {
代码示例来源:origin: goeasyway/EasyPlug
@Override
public File[] getExternalFilesDirs(String type) {
return hostContext.getExternalFilesDirs(type);
}
代码示例来源:origin: goeasyway/EasyPlug
@Override
public File[] getExternalFilesDirs(String type) {
return hostContext.getExternalFilesDirs(type);
}
代码示例来源:origin: kingargyle/adt-leanback-support
public static File[] getExternalFilesDirs(Context context, String type) {
return context.getExternalFilesDirs(type);
}
代码示例来源:origin: IvanVolosyuk/diskusage
@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;
}
代码示例来源:origin: souch/SMP
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;
}
代码示例来源:origin: kollerlukas/Camera-Roll-Android-App
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;
}
代码示例来源:origin: mkulesh/microMathematics
File[] ff = ctx.getExternalFilesDirs(null);
if (ff == null)
return null;
代码示例来源:origin: stackoverflow.com
File fileList2[] = _context.getExternalFilesDirs(Environment.DIRECTORY_DOWNLOADS);
代码示例来源:origin: stackoverflow.com
@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();
}
代码示例来源:origin: y20k/transistor
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;
}
代码示例来源:origin: proninyaroslav/libretorrent
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;
}
代码示例来源:origin: easefun/polyv-android-sdk-2.0-demo
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
files = context.getExternalFilesDirs(null);
} else {
files = ContextCompat.getExternalFilesDirs(context, null);
代码示例来源:origin: stackoverflow.com
File[] files = context.getExternalFilesDirs(null);
for (File file : files) {
String applicationSpecificAbsolutePath = file.getAbsolutePath();
代码示例来源:origin: saki4510t/libcommon
final File[] dirs = context.getExternalFilesDirs(null);
final int n = dirs != null ? dirs.length : 0;
final StringBuilder sb = new StringBuilder();
内容来源于网络,如有侵权,请联系作者删除!