本文整理了Java中android.os.Environment.getExternalStorageDirectory()
方法的一些代码示例,展示了Environment.getExternalStorageDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.getExternalStorageDirectory()
方法的具体详情如下:
包路径:android.os.Environment
类名称:Environment
方法名:getExternalStorageDirectory
暂无
代码示例来源:origin: jeasonlzy/okhttp-OkGo
public FileConvert(String fileName) {
this(Environment.getExternalStorageDirectory() + DM_TARGET_FOLDER, fileName);
}
代码示例来源:origin: Curzibn/Luban
/**
* <b>BuildTime:</b> 2014-10-22<br>
* <b>Description:</b> get SDCard path<br>
*
* @return String of path
*/
public static String getSDCardPath() {
return Environment.getExternalStorageDirectory().getPath();
}
代码示例来源:origin: Curzibn/Luban
private String getPath() {
String path = Environment.getExternalStorageDirectory() + "/Luban/image/";
File file = new File(path);
if (file.mkdirs()) {
return path;
}
return path;
}
代码示例来源:origin: facebook/stetho
private static File resolvePossibleSdcardPath(String path) {
if (path.startsWith("/")) {
return new File(path);
} else {
return new File(Environment.getExternalStorageDirectory(), path);
}
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
private static File getExternalCacheDir(Context context) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
if (!appCacheDir.exists()) {
if (!appCacheDir.mkdirs()) {
return null;
}
}
return appCacheDir;
}
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
private static File getExternalCacheDir(Context context) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
if (!appCacheDir.exists()) {
if (!appCacheDir.mkdirs()) {
HttpProxyCacheDebuger.printfWarning("Unable to create external cache directory");
return null;
}
}
return appCacheDir;
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected File getExternalCacheDir() {
return Environment.getExternalStorageDirectory();
}
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
/**
* Returns specified application cache directory. Cache directory will be created on SD card by defined path if card
* is mounted and app has appropriate permission. Else - Android defines cache directory on device's file system.
*
* @param context Application context
* @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images")
* @return Cache {@link File directory}
*/
public static File getOwnCacheDirectory(Context context, String cacheDir) {
File appCacheDir = null;
if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
appCacheDir = new File(Environment.getExternalStorageDirectory(), cacheDir);
}
if (appCacheDir == null || (!appCacheDir.exists() && !appCacheDir.mkdirs())) {
appCacheDir = context.getCacheDir();
}
return appCacheDir;
}
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
/**
* Returns specified application cache directory. Cache directory will be created on SD card by defined path if card
* is mounted and app has appropriate permission. Else - Android defines cache directory on device's file system.
*
* @param context Application context
* @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images")
* @return Cache {@link File directory}
*/
public static File getOwnCacheDirectory(Context context, String cacheDir, boolean preferExternal) {
File appCacheDir = null;
if (preferExternal && MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
appCacheDir = new File(Environment.getExternalStorageDirectory(), cacheDir);
}
if (appCacheDir == null || (!appCacheDir.exists() && !appCacheDir.mkdirs())) {
appCacheDir = context.getCacheDir();
}
return appCacheDir;
}
代码示例来源:origin: android-hacker/VirtualXposed
public static File getVirtualStorageBaseDir() {
File externalFilesRoot = Environment.getExternalStorageDirectory();
if (externalFilesRoot != null) {
File vBaseDir = new File(externalFilesRoot, "VirtualXposed");
File vSdcard = new File(vBaseDir, "vsdcard");
return ensureCreated(vSdcard);
}
return null;
}
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
private static File getExternalCacheDir(Context context) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
if (!appCacheDir.exists()) {
if (!appCacheDir.mkdirs()) {
L.w("Unable to create external cache directory");
return null;
}
try {
new File(appCacheDir, ".nomedia").createNewFile();
} catch (IOException e) {
L.i("Can't create \".nomedia\" file in application external cache directory");
}
}
return appCacheDir;
}
代码示例来源:origin: TeamNewPipe/NewPipe
public File getBackTop() {
if (getArguments() == null) return Environment.getExternalStorageDirectory();
final String path = getArguments().getString(KEY_START_PATH, "/");
if (path.contains(Environment.getExternalStorageDirectory().getPath())) {
return Environment.getExternalStorageDirectory();
}
return getPath(path);
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
protected AbstractFilePickerFragment<File> getFragment(@Nullable String startPath, int mode, boolean allowMultiple, boolean allowCreateDir, boolean allowExistingFile, boolean singleClick) {
final CustomFilePickerFragment fragment = new CustomFilePickerFragment();
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
return currentFragment = fragment;
}
代码示例来源:origin: android-hacker/VirtualXposed
public static File getVirtualPrivateStorageDir(int userId) {
String base = String.format(Locale.ENGLISH, "%s/Android/data/%s/%s/%d", Environment.getExternalStorageDirectory(),
VirtualCore.get().getHostPkg(), "virtual", userId);
File file = new File(base);
return ensureCreated(file);
}
代码示例来源:origin: greenrobot/greenDAO
private File getBenchFile(String name) {
File dir = Environment.getExternalStorageDirectory();
File file = new File(dir, name);
if (dir == null || !dir.canWrite()) {
Application app = createApplication(Application.class);
File appFile = new File(app.getFilesDir(), name);
DaoLog.d("Using file " + appFile.getAbsolutePath() + ", (cannot write to " + file.getAbsolutePath() + ")");
file = appFile;
}
return file;
}
代码示例来源:origin: Justson/AgentWeb
public static long getAvailableStorage() {
try {
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}
} catch (RuntimeException ex) {
return 0;
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getExternalStorageDirectory_shouldReturnDirectory() {
assertThat(Environment.getExternalStorageDirectory().exists()).isTrue();
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
private OkDownload() {
folder = Environment.getExternalStorageDirectory() + File.separator + "download" + File.separator;
IOUtils.createFolder(folder);
threadPool = new DownloadThreadPool();
taskMap = new ConcurrentHashMap<>();
//校验数据的有效性,防止下载过程中退出,第二次进入的时候,由于状态没有更新导致的状态错误
List<Progress> taskList = DownloadManager.getInstance().getDownloading();
for (Progress info : taskList) {
if (info.status == Progress.WAITING || info.status == Progress.LOADING || info.status == Progress.PAUSE) {
info.status = Progress.NONE;
}
}
DownloadManager.getInstance().replace(taskList);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = LOLLIPOP)
public void storageIsLazy() {
assertNull(ShadowEnvironment.EXTERNAL_CACHE_DIR);
assertNull(ShadowEnvironment.EXTERNAL_FILES_DIR);
Environment.getExternalStorageDirectory();
Environment.getExternalStoragePublicDirectory(null);
assertNotNull(ShadowEnvironment.EXTERNAL_CACHE_DIR);
assertNotNull(ShadowEnvironment.EXTERNAL_FILES_DIR);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = M)
public void isExternalStorageRemovable_primaryShouldReturnSavedValue() {
assertThat(Environment.isExternalStorageRemovable()).isFalse();
ShadowEnvironment.setExternalStorageRemovable(Environment.getExternalStorageDirectory(), true);
assertThat(Environment.isExternalStorageRemovable()).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!