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


Java Environment.isExternalStorageEmulated方法代码示例

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


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

示例1: getDrives

import android.os.Environment; //导入方法依赖的package包/类
public static Map<File,String> getDrives() {
    File r = new File("/storage");


    Map<File,String> files = new LinkedHashMap<>();

    int sd = 1;
    for (File e: r.listFiles()) {
        Log.d("storage", e.getPath() + " " + e.isDirectory());
        if (e.isDirectory() && !e.getName().equals("emulated") && !e.getName().equals("self")) {
            String name = "SD";
            if (sd++>1) name += sd;
            files.put(e, Environment.isExternalStorageRemovable(e) ? name : e.getName());
        }
    }

    File ext = Environment.getExternalStorageDirectory();
    if (Environment.isExternalStorageEmulated()) {
        files.put(ext, "Internal");
    } else if (Environment.isExternalStorageRemovable()) {
        files.put(ext, "SD");
    }

    return files;
}
 
开发者ID:quaap,项目名称:BookyMcBookface,代码行数:26,代码来源:FsTools.java

示例2: buildMountsList

import android.os.Environment; //导入方法依赖的package包/类
/**
 * Converts a list of mount strings to a list of Storage items
 * @param context the context
 * @param mounts a list of mount points as strings
 * @return a list of Storage items that can be rendered by the ui
 */
private static List<Storage> buildMountsList(Context context, List<String> mounts) {
  List<Storage> list = new ArrayList<>(mounts.size());

  int externalSdcardsCount = 0;
  if (mounts.size() > 0) {
    // Follow Android SD Cards naming conventions
    if (!Environment.isExternalStorageRemovable() || Environment.isExternalStorageEmulated()) {
      list.add(new Storage(context.getString(R.string.prefs_sdcard_internal),
          Environment.getExternalStorageDirectory().getAbsolutePath()));
    } else {
      externalSdcardsCount = 1;
      list.add(new Storage(context.getString(R.string.prefs_sdcard_external,
          externalSdcardsCount), mounts.get(0)));
    }

    // All other mounts rather than the first mount point are considered as External SD Card
    if (mounts.size() > 1) {
      externalSdcardsCount++;
      for (int i = 1/*skip the first item*/; i < mounts.size(); i++) {
        list.add(new Storage(context.getString(R.string.prefs_sdcard_external,
            externalSdcardsCount++), mounts.get(i)));
      }
    }
  }

  Timber.d("final storage list is: %s", list);
  return list;
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:35,代码来源:StorageUtils.java

示例3: buildMountsList

import android.os.Environment; //导入方法依赖的package包/类
/**
 * Converts a list of mount strings to a list of Storage items
 *
 * @param context the context
 * @param mounts  a list of mount points as strings
 * @return a list of Storage items that can be rendered by the ui
 */
private static List<Storage> buildMountsList(Context context, List<String> mounts) {
    List<Storage> list = new ArrayList<>(mounts.size());

    int externalSdcardsCount = 0;
    if (mounts.size() > 0) {
        // Follow Android SD Cards naming conventions
        if (!Environment.isExternalStorageRemovable() || Environment.isExternalStorageEmulated()) {
            list.add(new Storage(context.getString(R.string.prefs_sdcard_internal),
                    Environment.getExternalStorageDirectory().getAbsolutePath()));
        } else {
            externalSdcardsCount = 1;
            list.add(new Storage(context.getString(R.string.prefs_sdcard_external,
                    externalSdcardsCount), mounts.get(0)));
        }

        // All other mounts rather than the first mount point are considered as External SD Card
        if (mounts.size() > 1) {
            externalSdcardsCount++;
            for (int i = 1/*skip the first item*/; i < mounts.size(); i++) {
                list.add(new Storage(context.getString(R.string.prefs_sdcard_external,
                        externalSdcardsCount++), mounts.get(i)));
            }
        }
    }

    Timber.d("final storage list is: %s", list);
    return list;
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:36,代码来源:StorageUtils.java

示例4: addInterceptor

import android.os.Environment; //导入方法依赖的package包/类
private static OkHttpClient.Builder addInterceptor() {
    if (INTERCEPTORS != null) {
        for (Interceptor interceptor : INTERCEPTORS) {
            if (!(isApiTest && interceptor instanceof ApiTestInterceptor)) {
                break;
            } else {
                BUILDER.addInterceptor(interceptor);
            }
        }
    }

    final boolean isCache = AvenueNet.getConfig(ConfigKey.COMMON_CACHE);
    if (isCache) {
        final Context context = AvenueNet.getAppContext();
        final int size = 5 * 1024;
        final File cacheFile;
        if (Environment.isExternalStorageEmulated()) {
            cacheFile = context.getExternalCacheDir();
        } else {
            cacheFile = context.getCacheDir();
        }
        final Cache cache = new Cache(cacheFile, size);
        final CacheInterceptor cacheInterceptor = new CacheInterceptor();
        BUILDER.addNetworkInterceptor(cacheInterceptor);
        BUILDER.cache(cache);
        BUILDER.addInterceptor(cacheInterceptor);
    }
    return BUILDER;
}
 
开发者ID:QuincySx,项目名称:AvenueNet,代码行数:30,代码来源:NetClientCreator.java

示例5: getDiskCacheDir

import android.os.Environment; //导入方法依赖的package包/类
/**
 * 获取缓存的路径
 *
 * @param uniqueName
 * @return
 */
private File getDiskCacheDir(String uniqueName) {
    boolean isSDCardMounted = Environment.isExternalStorageEmulated();
    boolean isSDCardUnRemovable = Environment.isExternalStorageRemovable();
    String path;
    if (isSDCardMounted || isSDCardUnRemovable) {
        path = mContext.getExternalCacheDir().getPath();
    } else {
        path = mContext.getCacheDir().getPath();
    }
    File file = new File(path + File.separator + uniqueName);
    if (!file.exists())
        file.mkdirs();
    return file;
}
 
开发者ID:iPanelkegy,项目名称:MobileMedia,代码行数:21,代码来源:ImageLoader.java

示例6: getAllStorageLocations

import android.os.Environment; //导入方法依赖的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

示例7: getAllStorageLocations

import android.os.Environment; //导入方法依赖的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

示例8: isMounted

import android.os.Environment; //导入方法依赖的package包/类
/**
 * 判断SD卡是否mounted
 */
@SuppressLint("NewApi")
public static boolean isMounted() {
    return Environment.isExternalStorageEmulated();
}
 
开发者ID:pre-dem,项目名称:pre-dem-android,代码行数:8,代码来源:LogUtils.java

示例9: isMounted

import android.os.Environment; //导入方法依赖的package包/类
/** 判断SD卡是否mounted*/
public static boolean isMounted() {
    return Environment.isExternalStorageEmulated();
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:5,代码来源:LogUtil.java

示例10: isExternalStorageEmulated

import android.os.Environment; //导入方法依赖的package包/类
public static boolean isExternalStorageEmulated()
{
    return Environment.isExternalStorageEmulated();
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:5,代码来源:CompatUtils.java

示例11: setProperties

import android.os.Environment; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@SuppressWarnings("unchecked")
   private static void setProperties() {
       /*
        * At this point all the paths in the list should be valid. Build the
        * public properties.
        */
       mLabels = new ArrayList<String>();

       int j = 0;
       if (mMounts.size() > 0) {
           if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD)
               mLabels.add(AppSmartMath.getContext().getString(R.string.auto));
           else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
               if (Environment.isExternalStorageRemovable()) {
                   mLabels.add(AppSmartMath.getContext().getString(R.string.external_sd_card) + " 1");
                   j = 1;
               } else
                   mLabels.add(AppSmartMath.getContext().getString(R.string.internal_storage));
           } else {
               if (!Environment.isExternalStorageRemovable()
                       || Environment.isExternalStorageEmulated())
                   mLabels.add(AppSmartMath.getContext().getString(R.string.internal_storage));
               else {
                   mLabels.add(AppSmartMath.getContext().getString(R.string.external_sd_card) + " 1");
                   j = 1;
               }
           }

           if (mMounts.size() > 1) {
               for (int i = 1; i < mMounts.size(); i++) {
                   mLabels.add(AppSmartMath.getContext().getString(R.string.external_sd_card)  + (i + j));
               }
           }
       }

       labels = new String[mLabels.size()];
       mLabels.toArray(labels);

       paths = new String[mMounts.size()];
       mMounts.toArray(paths);
       count = Math.min(labels.length, paths.length);

   }
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:45,代码来源:AndroidStorageOptions.java


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