本文整理汇总了Java中android.os.Environment.getStorageState方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.getStorageState方法的具体用法?Java Environment.getStorageState怎么用?Java Environment.getStorageState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Environment
的用法示例。
在下文中一共展示了Environment.getStorageState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStorageState
import android.os.Environment; //导入方法依赖的package包/类
private String getStorageState(File path) {
if(path.getAbsolutePath().startsWith(KernalConstants.baseContext.getFilesDir().getAbsolutePath())){
return MEDIA_MOUNTED;
}
final int version = Build.VERSION.SDK_INT;
if (version >= 19) {
return Environment.getStorageState(path);
}
try {
final String canonicalPath = path.getCanonicalPath();
final String canonicalExternal = Environment.getExternalStorageDirectory()
.getCanonicalPath();
if (canonicalPath.startsWith(canonicalExternal)) {
return Environment.getExternalStorageState();
}
} catch (IOException e) {
}
return MEDIA_UNKNOWN;
}
示例2: getStorageState
import android.os.Environment; //导入方法依赖的package包/类
public static String getStorageState(File path) {
final int version = Build.VERSION.SDK_INT;
if (version >= 19) {
return Environment.getStorageState(path);
}
try {
final String canonicalPath = path.getCanonicalPath();
final String canonicalExternal = Environment.getExternalStorageDirectory()
.getCanonicalPath();
if (canonicalPath.startsWith(canonicalExternal)) {
return Environment.getExternalStorageState();
}
} catch (IOException e) {
}
return MEDIA_UNKNOWN;
}
示例3: updateVolumesLocked
import android.os.Environment; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private void updateVolumesLocked() {
mRoots.clear();
mIdToPath.clear();
mIdToRoot.clear();
int count = 0;
StorageUtils storageUtils = new StorageUtils(getContext());
for (StorageVolume volume : storageUtils.getStorageMounts()) {
final File path = volume.getPathFile();
if(Utils.hasKitKat()){
String state = Environment.getStorageState(path);
final boolean mounted = Environment.MEDIA_MOUNTED.equals(state)
|| Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
if (!mounted) continue;
}
final String rootId;
if (volume.isPrimary() && volume.isEmulated()) {
rootId = ROOT_ID_PRIMARY_EMULATED;
} else if (volume.getUuid() != null) {
rootId = ROOT_ID_SECONDARY + volume.getUserLabel();
} else {
Log.d(TAG, "Missing UUID for " + volume.getPath() + "; skipping");
continue;
}
if (mIdToPath.containsKey(rootId)) {
Log.w(TAG, "Duplicate UUID " + rootId + "; skipping");
continue;
}
try {
if(null == path.listFiles()){
continue;
}
mIdToPath.put(rootId, path);
final RootInfo root = new RootInfo();
root.rootId = rootId;
root.flags = Document.FLAG_SUPPORTS_THUMBNAIL;
if (ROOT_ID_PRIMARY_EMULATED.equals(rootId)) {
root.title = getContext().getString(R.string.root_internal_storage);
} else {
count++;
root.title = getContext().getString(R.string.root_external_storage) + " " + count;// + volume.getLabel();
}
root.docId = getDocIdForFile(path);
mRoots.add(root);
mIdToRoot.put(rootId, root);
} catch (FileNotFoundException e) {
throw new IllegalStateException(e);
}
}
Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots");
getContext().getContentResolver()
.notifyChange(DocumentsContract.buildRootsUri(AUTHORITY), null, false);
}
示例4: getStorageState
import android.os.Environment; //导入方法依赖的package包/类
public static String getStorageState(File path) {
return Environment.getStorageState(path);
}