當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment.getStorageState方法代碼示例

本文整理匯總了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;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:23,代碼來源:KernalVersionManager.java

示例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;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:20,代碼來源:Framework.java

示例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);
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:60,代碼來源:HeatMapProvider.java

示例4: getStorageState

import android.os.Environment; //導入方法依賴的package包/類
public static String getStorageState(File path) {
    return Environment.getStorageState(path);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:4,代碼來源:EnvironmentCompatKitKat.java


注:本文中的android.os.Environment.getStorageState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。