本文整理匯總了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);
}