当前位置: 首页>>代码示例>>Java>>正文


Java ContextCompat.getExternalFilesDirs方法代码示例

本文整理汇总了Java中android.support.v4.content.ContextCompat.getExternalFilesDirs方法的典型用法代码示例。如果您正苦于以下问题:Java ContextCompat.getExternalFilesDirs方法的具体用法?Java ContextCompat.getExternalFilesDirs怎么用?Java ContextCompat.getExternalFilesDirs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.content.ContextCompat的用法示例。


在下文中一共展示了ContextCompat.getExternalFilesDirs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExternalFilesDir

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public File getExternalFilesDir() throws IOException {
    File tempFile = null;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        String state = Environment.getExternalStorageState();

        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // compatible for ALL the versions
            File[] dirs = ContextCompat.getExternalFilesDirs(context, null); //null, no specific sub directory
            if (dirs.length > 0) {
                tempFile  = dirs[dirs.length -1];
            }
        }
    } else {
        tempFile = Environment.getExternalStorageDirectory();
    }

    if (tempFile == null) {
        throw new IOException("External file could not be initialized!");
    } else {
        return tempFile;
    }
}
 
开发者ID:AbyxBelgium,项目名称:Loyalty,代码行数:24,代码来源:FileManager.java

示例2: getRootDirPath

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static String getRootDirPath(Context context) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        File file = ContextCompat.getExternalFilesDirs(context.getApplicationContext(), null)[0];
        return file.getAbsolutePath();
    } else {
        return context.getApplicationContext().getFilesDir().getAbsolutePath();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Utils.java

示例3: getRootDirPath

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static String getRootDirPath(Context context) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        File file = ContextCompat.getExternalFilesDirs(context.getApplicationContext(),
                null)[0];
        return file.getAbsolutePath();
    } else {
        return context.getApplicationContext().getFilesDir().getAbsolutePath();
    }
}
 
开发者ID:MindorksOpenSource,项目名称:PRDownloader,代码行数:10,代码来源:Utils.java

示例4: getVer4_4DownloadPath

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static String getVer4_4DownloadPath(Context context) {
    File[] dirs = ContextCompat.getExternalFilesDirs(context, null);
    LogInfo.log("ljnalex", "dirs.length:" + dirs.length);
    if (dirs == null || dirs.length == 0) {
        return "";
    }
    if (isSdcardAvailable() && dirs.length >= 2 && dirs[1] != null) {
        return dirs[1].getAbsolutePath();
    }
    if (isSdcardAvailable() || dirs[0] == null) {
        return "";
    }
    return dirs[0].getAbsolutePath();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:15,代码来源:StoreUtils.java

示例5: getFilePath

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
 * Return the absolute file path for a file in the app directory
 * @param fileName - String representing file name
 * @return String representing the absolute path to the file
 */
private String getFilePath(final String fileName){
  String filepath = null;
  final File [] dirFiles = ContextCompat.getExternalFilesDirs(mContext, null);

  // We don't encrypt files if we can't store them...
  if (dirFiles.length == 0){
    Log.i(TAG, "Data cannot be encrypted because no app directories were found.");
    return filepath;
  }else{
    final File f = dirFiles[0];
    filepath = f.getAbsolutePath() + File.separator + fileName;
  }
  return filepath;
}
 
开发者ID:Esri,项目名称:mapbook-android,代码行数:20,代码来源:CredentialCryptographer.java

示例6: providesStorageDirectory

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
@Provides
@MapbookApplicationScope
@Named("storageDirectory")
public File providesStorageDirectory(final Context context) {
  File directory = null;
  final File [] files = ContextCompat.getExternalFilesDirs(context, null);
  if (files.length > 0){
    directory = files[0];
  }else{
    directory = Environment.getDataDirectory();
  }
  return directory;
}
 
开发者ID:Esri,项目名称:mapbook-android,代码行数:14,代码来源:MapbookModule.java

示例7: getAllStorageLocations

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
 * @return A List of all storage locations available
 */
public static List<Storage> getAllStorageLocations(Context context) {

  /*
    This first condition is the code moving forward, since the else case is a bunch
    of unsupported hacks.

    For Kitkat and above, we rely on Environment.getExternalFilesDirs to give us a list
    of application writable directories (none of which require WRITE_EXTERNAL_STORAGE on
    Kitkat and above).

    Previously, we only would show anything if there were at least 2 entries. For M,
    some changes were made, such that on M, we even show this if there is only one
    entry.

    Irrespective of whether we require 1 entry (M) or 2 (Kitkat and L), we add an
    additional entry explicitly for the sdcard itself, (the one requiring
    WRITE_EXTERNAL_STORAGE to write).

    Thus, on Kitkat, the user may either:
    a. not see any item (if there's only one entry returned by getExternalFilesDirs, we won't
    show any options since it's the same sdcard and we have the permission and the user can't
    revoke it pre-Kitkat), or
    b. see 3+ items - /sdcard, and then at least 2 external fiels directories.

    on M, the user will always see at least 2 items (the external files dir and the actual
    external storage directory), and potentially more (depending on how many items are returned
    by getExternalFilesDirs).
   */
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    List<Storage> result = new ArrayList<>();
    int limit = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 1 : 2;
    final File[] mountPoints = ContextCompat.getExternalFilesDirs(context, null);
    if (mountPoints != null && mountPoints.length >= limit) {
      int typeId;
      if (!Environment.isExternalStorageRemovable() || Environment.isExternalStorageEmulated()) {
        typeId = R.string.prefs_sdcard_internal;
      } else {
        typeId = R.string.prefs_sdcard_external;
      }

      int number = 1;
      result.add(new Storage(context.getString(typeId, number),
          Environment.getExternalStorageDirectory().getAbsolutePath(),
          Build.VERSION.SDK_INT >= Build.VERSION_CODES.M));
      for (File mountPoint : mountPoints) {
        result.add(new Storage(context.getString(typeId, number++),
            mountPoint.getAbsolutePath()));
        typeId = R.string.prefs_sdcard_external;
      }
    }
    return result;
  } else {
    return getLegacyStorageLocations(context);
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:59,代码来源:StorageUtils.java

示例8: getAllStorageLocations

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
 * @return A List of all storage locations available
 */
public static List<Storage> getAllStorageLocations(Context context) {

/*
  This first condition is the code moving forward, since the else case is a bunch
  of unsupported hacks.

  For Kitkat and above, we rely on Environment.getExternalFilesDirs to give us a list
  of application writable directories (none of which require WRITE_EXTERNAL_STORAGE on
  Kitkat and above).

  Previously, we only would show anything if there were at least 2 entries. For M,
  some changes were made, such that on M, we even show this if there is only one
  entry.

  Irrespective of whether we require 1 entry (M) or 2 (Kitkat and L), we add an
  additional entry explicitly for the sdcard itself, (the one requiring
  WRITE_EXTERNAL_STORAGE to write).

  Thus, on Kitkat, the user may either:
  a. not see any item (if there's only one entry returned by getExternalFilesDirs, we won't
  show any options since it's the same sdcard and we have the permission and the user can't
  revoke it pre-Kitkat), or
  b. see 3+ items - /sdcard, and then at least 2 external fiels directories.

  on M, the user will always see at least 2 items (the external files dir and the actual
  external storage directory), and potentially more (depending on how many items are returned
  by getExternalFilesDirs).
 */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        List<Storage> result = new ArrayList<>();
        int limit = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 1 : 2;
        final File[] mountPoints = ContextCompat.getExternalFilesDirs(context, null);
        if (mountPoints != null && mountPoints.length >= limit) {
            int typeId;
            if (!Environment.isExternalStorageRemovable() || Environment.isExternalStorageEmulated()) {
                typeId = R.string.prefs_sdcard_internal;
            } else {
                typeId = R.string.prefs_sdcard_external;
            }

            int number = 1;
            result.add(new Storage(context.getString(typeId, number),
                    Environment.getExternalStorageDirectory().getAbsolutePath(),
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.M));
            for (File mountPoint : mountPoints) {
                result.add(new Storage(context.getString(typeId, number++),
                        mountPoint.getAbsolutePath()));
                typeId = R.string.prefs_sdcard_external;
            }
        }
        return result;
    } else {
        return getLegacyStorageLocations(context);
    }
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:59,代码来源:StorageUtils.java


注:本文中的android.support.v4.content.ContextCompat.getExternalFilesDirs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。