本文整理匯總了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);
}