本文整理汇总了Java中android.content.Context.getExternalFilesDirs方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getExternalFilesDirs方法的具体用法?Java Context.getExternalFilesDirs怎么用?Java Context.getExternalFilesDirs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.getExternalFilesDirs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtSdCardDataPaths
import android.content.Context; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private String[] getExtSdCardDataPaths(Context context) {
List<String> paths = new ArrayList<String>();
for (File file : context.getExternalFilesDirs("external")) {
if (file != null) {
int index = file.getAbsolutePath().lastIndexOf("/Android/data");
if (index >= 0) {
String path = file.getAbsolutePath().substring(0, index);
try {
path = new File(path).getCanonicalPath();
} catch (IOException e) {
// Keep non-canonical path.
}
paths.add(path);
}
}
}
if (paths.isEmpty()) paths.add("/storage/sdcard1");
return paths.toArray(new String[0]);
}
示例2: getRemovableStorageRoots
import android.content.Context; //导入方法依赖的package包/类
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;
}
示例3: setEnv
import android.content.Context; //导入方法依赖的package包/类
@Override
public void setEnv(final Context p) {
File[] paths = p.getExternalFilesDirs(null);
int index = 0;
for (File path : paths) {
if (path == null)
continue;
if (!path.exists())
path.mkdirs();
nativeSetEnv("UNSECURE_STORAGE_DIR_" + index, path.getAbsolutePath());
index++;
}
}
示例4: allPaths
import android.content.Context; //导入方法依赖的package包/类
@Override
public String[] allPaths(final Context p) {
ArrayList<String> ret = new ArrayList<String>();
for (File path : p.getExternalFilesDirs(null)) {
if (path == null)
continue;
try {
path.mkdirs();
new FileOutputStream(new File(path, ".nomedia")).close();
} catch (Exception e) {
continue;
}
ret.add(path.getAbsolutePath());
}
return ret.toArray(new String[0]);
}
示例5: getExternalFilesDirs
import android.content.Context; //导入方法依赖的package包/类
public static File[] getExternalFilesDirs(Context context, String type) {
final int version = Build.VERSION.SDK_INT;
if (version >= 19) {
//返回结果可能存在null值
return context.getExternalFilesDirs(type);
} else {
return new File[] { context.getExternalFilesDir(type) };
}
}
示例6: getExternalFilesDirs
import android.content.Context; //导入方法依赖的package包/类
public static File[] getExternalFilesDirs(Context context, String type) {
if (Build.VERSION.SDK_INT >= 19) {
return context.getExternalFilesDirs(type);
} else {
return new File[]{context.getExternalFilesDir(type)};
}
}
示例7: getExternalFilesDirs
import android.content.Context; //导入方法依赖的package包/类
public static File[] getExternalFilesDirs(Context context) {
File[] files;
files = context.getExternalFilesDirs(null);
if (files == null) {
files = new File[0];
}
return files;
}
示例8: getStorageDirs
import android.content.Context; //导入方法依赖的package包/类
/**
* Procedure retrieves the storage directory
*/
public static String[] getStorageDirs(Context ctx)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
File[] ff = ctx.getExternalFilesDirs(null);
if (ff == null)
return null;
String[] res = new String[ff.length];
for (int i = 0; i < ff.length; i++)
{
if (ff[i] == null)
continue;
String path = ff[i].getAbsolutePath();
if (path == null)
continue;
int pos = path.indexOf("Android");
if (pos < 0)
{
continue;
}
res[i] = path.substring(0, pos);
}
return res;
}
else
{
return null;
}
}
示例9: getExternalFilesDirs
import android.content.Context; //导入方法依赖的package包/类
public static File[] getExternalFilesDirs(Context context, String type) {
return context.getExternalFilesDirs(type);
}