android.os.Environment.isExternalStorageRemovable()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(281)

本文整理了Java中android.os.Environment.isExternalStorageRemovable()方法的一些代码示例,展示了Environment.isExternalStorageRemovable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.isExternalStorageRemovable()方法的具体详情如下:
包路径:android.os.Environment
类名称:Environment
方法名:isExternalStorageRemovable

Environment.isExternalStorageRemovable介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. @Config(minSdk = LOLLIPOP)
  3. public void isExternalStorageRemovable_shouldReturnSavedValue() {
  4. final File file = new File("/mnt/media/file");
  5. assertThat(Environment.isExternalStorageRemovable(file)).isFalse();
  6. ShadowEnvironment.setExternalStorageRemovable(file, true);
  7. assertThat(Environment.isExternalStorageRemovable(file)).isTrue();
  8. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. @Config(minSdk = M)
  3. public void isExternalStorageRemovable_primaryShouldReturnSavedValue() {
  4. assertThat(Environment.isExternalStorageRemovable()).isFalse();
  5. ShadowEnvironment.setExternalStorageRemovable(Environment.getExternalStorageDirectory(), true);
  6. assertThat(Environment.isExternalStorageRemovable()).isTrue();
  7. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. @Config(minSdk = LOLLIPOP)
  3. public void reset_shouldClearRemovableFiles() {
  4. final File file = new File("foo");
  5. ShadowEnvironment.setExternalStorageRemovable(file, true);
  6. assertThat(Environment.isExternalStorageRemovable(file)).isTrue();
  7. ShadowEnvironment.reset();
  8. assertThat(Environment.isExternalStorageRemovable(file)).isFalse();
  9. }

代码示例来源:origin: Cleveroad/AdaptiveTableLayout

  1. return Environment.getExternalStorageDirectory() + "/" + split[1];
  2. } else {
  3. if (Environment.isExternalStorageRemovable()) {
  4. storageDefinition = "EXTERNAL_STORAGE";
  5. } else {

代码示例来源:origin: joyoyao/superCleanMaster

  1. public static SDCardInfo getSDCardInfo() {
  2. // String sDcString = Environment.getExternalStorageState();
  3. if (Environment.isExternalStorageRemovable()) {
  4. String sDcString = Environment.getExternalStorageState();
  5. if (sDcString.equals(Environment.MEDIA_MOUNTED)) {
  6. File pathFile = Environment
  7. .getExternalStorageDirectory();
  8. try {
  9. StatFs statfs = new StatFs(
  10. pathFile.getPath());
  11. // 获取SDCard上BLOCK总数
  12. long nTotalBlocks = statfs.getBlockCount();
  13. // 获取SDCard上每个block的SIZE
  14. long nBlocSize = statfs.getBlockSize();
  15. // 获取可供程序使用的Block的数量
  16. long nAvailaBlock = statfs.getAvailableBlocks();
  17. // 获取剩下的所有Block的数量(包括预留的一般程序无法使用的块)
  18. long nFreeBlock = statfs.getFreeBlocks();
  19. SDCardInfo info = new SDCardInfo();
  20. // 计算SDCard 总容量大小MB
  21. info.total = nTotalBlocks * nBlocSize;
  22. // 计算 SDCard 剩余大小MB
  23. info.free = nAvailaBlock * nBlocSize;
  24. return info;
  25. } catch (IllegalArgumentException e) {
  26. }
  27. }
  28. }
  29. return null;
  30. }

代码示例来源:origin: WVector/AppUpdate

  1. if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || !Environment.isExternalStorageRemovable()) {
  2. try {
  3. path = getActivity().getExternalCacheDir().getAbsolutePath();

代码示例来源:origin: WVector/AppUpdate

  1. if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || !Environment.isExternalStorageRemovable()) {
  2. try {
  3. path = getExternalCacheDir().getAbsolutePath();

代码示例来源:origin: limedroid/XDroidMvp

  1. private static File getDiskCacheDir(Context context, String dirName) {
  2. String cachePath;
  3. if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  4. || !Environment.isExternalStorageRemovable()) {
  5. cachePath = context.getExternalCacheDir().getPath();
  6. } else {
  7. cachePath = context.getCacheDir().getPath();
  8. }
  9. return new File(cachePath + File.separator + dirName);
  10. }

代码示例来源:origin: weexteam/weex-hackernews

  1. public static String getDiskCacheDir(Context context) {
  2. if (context == null) {
  3. return null;
  4. }
  5. String cachePath;
  6. if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  7. || !Environment.isExternalStorageRemovable()) {
  8. cachePath = context.getExternalCacheDir().getPath();
  9. } else {
  10. cachePath = context.getCacheDir().getPath();
  11. }
  12. return cachePath;
  13. }

代码示例来源:origin: chat-sdk/chat-sdk-android

  1. public static File getDiskCacheDir(Context context, String uniqueName) {
  2. // Check if media is mounted or storage is built-in, if so, try and use external cache dir
  3. // otherwise use internal cache dir
  4. final String cachePath =
  5. Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ||
  6. !isExternalStorageRemovable() ? context.getExternalCacheDir().getPath() :
  7. context.getCacheDir().getPath();
  8. if (uniqueName == null || uniqueName.isEmpty()) {
  9. uniqueName = context.getResources().getString(R.string.app_name);
  10. }
  11. return new File(cachePath + File.separator + uniqueName);
  12. }

代码示例来源:origin: GcsSloop/diycode

  1. /**
  2. * 获取磁盘缓存文件夹 优先获取外置磁盘
  3. *
  4. * @param context 上下文
  5. * @param uniqueName 自定义名字
  6. */
  7. public File getDiskCacheDir(Context context, String uniqueName) {
  8. String cachePath;
  9. if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  10. || !Environment.isExternalStorageRemovable()) {
  11. cachePath = context.getExternalCacheDir().getPath();
  12. } else {
  13. cachePath = context.getCacheDir().getPath();
  14. }
  15. File cacheDir = new File(cachePath + File.separator + uniqueName);
  16. if (!cacheDir.exists())
  17. cacheDir.mkdir();
  18. return cacheDir;
  19. }

代码示例来源:origin: gpfduoduo/AirPlay-Receiver-on-Android

  1. /**
  2. * Check if external storage is built-in or removable.
  3. *
  4. * @return True if external storage is removable (like an SD card), false
  5. * otherwise.
  6. */
  7. public static boolean isExternalStorageRemovable() {
  8. return Environment.isExternalStorageRemovable();
  9. }

代码示例来源:origin: IvanVolosyuk/diskusage

  1. @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  2. @Override
  3. public boolean isExternalStorageRemovable() {
  4. try {
  5. return Environment.isExternalStorageRemovable(file);
  6. } catch (Exception e) {
  7. return false;
  8. }
  9. }

代码示例来源:origin: tohodog/QSVideoPlayer

  1. /**
  2. * 检测SD卡是否存在
  3. */
  4. public static boolean checkSDCardExists() {
  5. return (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  6. || !Environment.isExternalStorageRemovable());
  7. }

代码示例来源:origin: FacePlusPlus/MegviiFacepp-Android-SDK

  1. /**
  2. * 获取cache目录
  3. */
  4. public static String getDiskCachePath(Context context) {
  5. if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
  6. return context.getExternalCacheDir().getPath();
  7. } else {
  8. return context.getCacheDir().getPath();
  9. }
  10. }

代码示例来源:origin: FussenYu/AppCache

  1. public String getCacheDir(Context context) {
  2. String cachePath;
  3. if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  4. || !Environment.isExternalStorageRemovable()) {
  5. cachePath = context.getExternalCacheDir().getPath();
  6. } else {
  7. cachePath = context.getCacheDir().getPath();
  8. }
  9. return cachePath;
  10. }

代码示例来源:origin: amahi/android

  1. private File getDiskCacheDir(Context context, String uniqueName) {
  2. // Check if media is mounted or storage is built-in, if so, try and use external cache dir
  3. // otherwise use internal cache dir
  4. final String cachePath =
  5. Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ||
  6. !isExternalStorageRemovable() ? context.getExternalCacheDir().getPath() :
  7. context.getCacheDir().getPath();
  8. return new File(cachePath + File.separator + uniqueName);
  9. }

代码示例来源:origin: Dpuntu/android-downloader

  1. /**
  2. * 判断外部SD卡是否存在
  3. *
  4. * @return 是否存在
  5. */
  6. protected static boolean isExternalStorage() {
  7. if (isSdCardExist() || !Environment.isExternalStorageRemovable()) {
  8. return true;
  9. } else {
  10. return false;
  11. }
  12. }

代码示例来源:origin: TedaLIEz/ParsingPlayer

  1. @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  2. public static boolean isExternalStorageRemovable() {
  3. if (hasGingerbread()) {
  4. return Environment.isExternalStorageRemovable();
  5. }
  6. return true;
  7. }

代码示例来源:origin: huangfangyi/FanXin

  1. /**
  2. * Check if external storage is built-in or removable.
  3. *
  4. * @return True if external storage is removable (like an SD card), false
  5. * otherwise.
  6. */
  7. @TargetApi(VERSION_CODES.GINGERBREAD)
  8. public static boolean isExternalStorageRemovable() {
  9. if (Utils.hasGingerbread()) {
  10. return Environment.isExternalStorageRemovable();
  11. }
  12. return true;
  13. }

相关文章