android.content.Context.getExternalMediaDirs()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(370)

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

Context.getExternalMediaDirs介绍

暂无

代码示例

代码示例来源:origin: oasisfeng/condom

@RequiresApi(LOLLIPOP) @Override public File[] getExternalMediaDirs() {
  return mBase.getExternalMediaDirs();
}

代码示例来源:origin: Trumeet/MiPushFramework

@RequiresApi(LOLLIPOP) @Override public File[] getExternalMediaDirs() {
  return mBase.getExternalMediaDirs();
}

代码示例来源:origin: vanilla-music/vanilla

/**
 * Returns the guessed media paths for this device
 *
 * @return array with guessed directories
 */
private static ArrayList<String> discoverDefaultMediaPaths(Context context) {
  ArrayList<String> defaultPaths = new ArrayList<>();
  // Try to discover media paths using getExternalMediaDirs() on 5.x and newer
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    for (File file : context.getExternalMediaDirs()) {
      // Seems to happen on some Samsung 5.x devices. :-(
      if (file == null)
        continue;
      String path = file.getAbsolutePath();
      int match = path.indexOf("/Android/media/"); // From Environment.DIR_ANDROID + Environment.DIR_MEDIA (both hidden)
      if (match >= 0)
        defaultPaths.add(path.substring(0, match));
    }
  }
  // Fall back to old API and some guessing if nothing was found (yet).
  if (defaultPaths.size() == 0) {
    // this should always exist
    defaultPaths.add(Environment.getExternalStorageDirectory().getAbsolutePath());
    // this *may* exist
    File sdCard = new File("/storage/sdcard1");
    if (sdCard.isDirectory())
      defaultPaths.add(sdCard.getAbsolutePath());
  }
  return defaultPaths;
}

代码示例来源:origin: nvllsvm/Audinaut

public static File getDefaultMusicDirectory(Context context) {
  if (DEFAULT_MUSIC_DIR == null) {
    File[] dirs;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      dirs = context.getExternalMediaDirs();
    } else {
      dirs = ContextCompat.getExternalFilesDirs(context, null);
    }
    DEFAULT_MUSIC_DIR = new File(getBestDir(dirs), "music");
    if (!DEFAULT_MUSIC_DIR.exists() && !DEFAULT_MUSIC_DIR.mkdirs()) {
      Log.e(TAG, "Failed to create default dir " + DEFAULT_MUSIC_DIR);
      // Some devices seem to have screwed up the new media directory API.  Go figure.  Try again with standard locations
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        dirs = ContextCompat.getExternalFilesDirs(context, null);
        DEFAULT_MUSIC_DIR = new File(getBestDir(dirs), "music");
        if (!DEFAULT_MUSIC_DIR.exists() && !DEFAULT_MUSIC_DIR.mkdirs()) {
          Log.e(TAG, "Failed to create default dir " + DEFAULT_MUSIC_DIR);
        } else {
          Log.w(TAG, "Stupid OEM's messed up media dir API added in 5.0");
        }
      }
    }
  }
  return DEFAULT_MUSIC_DIR;
}

代码示例来源:origin: nvllsvm/Audinaut

dirs = context.getExternalMediaDirs();
} else {
  dirs = ContextCompat.getExternalFilesDirs(context, null);

代码示例来源:origin: alhazmy13/MediaPicker

if (Build.VERSION.SDK_INT > 20) {
  File external[] = context.getExternalMediaDirs();
  if (external.length > 1) {
    filePath = external[1].getAbsolutePath();

代码示例来源:origin: pylerSM/XInternalSD

String externalSd = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  File[] dirs = context.getExternalMediaDirs();
  for (File dir : dirs) {
    if (dir == null || !dir.exists()) {

相关文章

微信公众号

最新文章

更多

Context类方法