Java Code Examples for android.os.Environment.getStorageState()

The following are Jave code examples for showing how to use getStorageState() of the android.os.Environment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: atlas   File: KernalVersionManager.java   View Source Code Vote up 6 votes
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;
}
 
Example 2
Project: atlas   File: Framework.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: easyfilemanager   File: HeatMapProvider.java   View Source Code Vote up 4 votes
@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);
}
 
Example 4
Project: FireFiles   File: HeatMapProvider.java   View Source Code Vote up 4 votes
@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);
}
 
Example 5
Project: boohee_v5.6   File: EnvironmentCompatKitKat.java   View Source Code Vote up 4 votes
public static String getStorageState(File path) {
    return Environment.getStorageState(path);
}
 
Example 6
Project: simple-share-android   File: HeatMapProvider.java   View Source Code Vote up 4 votes
@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);
}