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

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

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

Environment.isExternalStorageRemovable介绍

暂无

代码示例

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

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

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

@Test
@Config(minSdk = M)
public void isExternalStorageRemovable_primaryShouldReturnSavedValue() {
 assertThat(Environment.isExternalStorageRemovable()).isFalse();
 ShadowEnvironment.setExternalStorageRemovable(Environment.getExternalStorageDirectory(), true);
 assertThat(Environment.isExternalStorageRemovable()).isTrue();
}

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

@Test
@Config(minSdk = LOLLIPOP)
public void reset_shouldClearRemovableFiles() {
 final File file = new File("foo");
 ShadowEnvironment.setExternalStorageRemovable(file, true);
 assertThat(Environment.isExternalStorageRemovable(file)).isTrue();
 ShadowEnvironment.reset();
 assertThat(Environment.isExternalStorageRemovable(file)).isFalse();
}

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

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

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

public static SDCardInfo getSDCardInfo() {
  // String sDcString = Environment.getExternalStorageState();
  if (Environment.isExternalStorageRemovable()) {
    String sDcString = Environment.getExternalStorageState();
    if (sDcString.equals(Environment.MEDIA_MOUNTED)) {
      File pathFile = Environment
          .getExternalStorageDirectory();
      try {
        StatFs statfs = new StatFs(
            pathFile.getPath());
        // 获取SDCard上BLOCK总数
        long nTotalBlocks = statfs.getBlockCount();
        // 获取SDCard上每个block的SIZE
        long nBlocSize = statfs.getBlockSize();
        // 获取可供程序使用的Block的数量
        long nAvailaBlock = statfs.getAvailableBlocks();
        // 获取剩下的所有Block的数量(包括预留的一般程序无法使用的块)
        long nFreeBlock = statfs.getFreeBlocks();
        SDCardInfo info = new SDCardInfo();
        // 计算SDCard 总容量大小MB
        info.total = nTotalBlocks * nBlocSize;
        // 计算 SDCard 剩余大小MB
        info.free = nAvailaBlock * nBlocSize;
        return info;
      } catch (IllegalArgumentException e) {
      }
    }
  }
  return null;
}

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

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

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

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

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

private static File getDiskCacheDir(Context context, String dirName) {
  String cachePath;
  if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
      || !Environment.isExternalStorageRemovable()) {
    cachePath = context.getExternalCacheDir().getPath();
  } else {
    cachePath = context.getCacheDir().getPath();
  }
  return new File(cachePath + File.separator + dirName);
}

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

public static String getDiskCacheDir(Context context) {
 if (context == null) {
  return null;
 }
 String cachePath;
 if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
     || !Environment.isExternalStorageRemovable()) {
  cachePath = context.getExternalCacheDir().getPath();
 } else {
  cachePath = context.getCacheDir().getPath();
 }
 return cachePath;
}

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

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

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

/**
 * 获取磁盘缓存文件夹 优先获取外置磁盘
 *
 * @param context    上下文
 * @param uniqueName 自定义名字
 */
public File getDiskCacheDir(Context context, String uniqueName) {
  String cachePath;
  if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
      || !Environment.isExternalStorageRemovable()) {
    cachePath = context.getExternalCacheDir().getPath();
  } else {
    cachePath = context.getCacheDir().getPath();
  }
  File cacheDir = new File(cachePath + File.separator + uniqueName);
  if (!cacheDir.exists())
    cacheDir.mkdir();
  return cacheDir;
}

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

/**
 * Check if external storage is built-in or removable.
 * 
 * @return True if external storage is removable (like an SD card), false
 * otherwise.
 */
public static boolean isExternalStorageRemovable() {
  return Environment.isExternalStorageRemovable();
}

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean isExternalStorageRemovable() {
 try {
  return Environment.isExternalStorageRemovable(file);
 } catch (Exception e) {
  return false;
 }
}

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

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

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

/**
 * 获取cache目录
 */
public static String getDiskCachePath(Context context) {
  if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    return context.getExternalCacheDir().getPath();
  } else {
    return context.getCacheDir().getPath();
  }
}

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

public String getCacheDir(Context context) {
  String cachePath;
  if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
      || !Environment.isExternalStorageRemovable()) {
    cachePath = context.getExternalCacheDir().getPath();
  } else {
    cachePath = context.getCacheDir().getPath();
  }
  return cachePath;
}

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

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

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

/**
 * 判断外部SD卡是否存在
 *
 * @return 是否存在
 */
protected static boolean isExternalStorage() {
  if (isSdCardExist() || !Environment.isExternalStorageRemovable()) {
    return true;
  } else {
    return false;
  }
}

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

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static boolean isExternalStorageRemovable() {
  if (hasGingerbread()) {
    return Environment.isExternalStorageRemovable();
  }
  return true;
}

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

/**
 * Check if external storage is built-in or removable.
 * 
 * @return True if external storage is removable (like an SD card), false
 *         otherwise.
 */
@TargetApi(VERSION_CODES.GINGERBREAD)
public static boolean isExternalStorageRemovable() {
  if (Utils.hasGingerbread()) {
    return Environment.isExternalStorageRemovable();
  }
  return true;
}

相关文章