本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例8: isMounted
import android.os.Environment; //導入方法依賴的package包/類
/**
* 判斷SD卡是否mounted
*/
@SuppressLint("NewApi")
public static boolean isMounted() {
return Environment.isExternalStorageEmulated();
}
示例9: isMounted
import android.os.Environment; //導入方法依賴的package包/類
/** 判斷SD卡是否mounted*/
public static boolean isMounted() {
return Environment.isExternalStorageEmulated();
}
示例10: isExternalStorageEmulated
import android.os.Environment; //導入方法依賴的package包/類
public static boolean isExternalStorageEmulated()
{
return Environment.isExternalStorageEmulated();
}
示例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);
}