Search in sources :

Example 56 with StorageVolume

use of android.os.storage.StorageVolume in project android_frameworks_base by crdroidandroid.

the class PackageHelper method fitsOnExternal.

public static boolean fitsOnExternal(Context context, long sizeBytes) {
    final StorageManager storage = context.getSystemService(StorageManager.class);
    final StorageVolume primary = storage.getPrimaryVolume();
    return (sizeBytes > 0) && !primary.isEmulated() && Environment.MEDIA_MOUNTED.equals(primary.getState()) && sizeBytes <= storage.getStorageBytesUntilLow(primary.getPathFile());
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager)

Example 57 with StorageVolume

use of android.os.storage.StorageVolume in project BlogSource by TeachCourse.

the class WriteToReadActivity method takePhoto.

/**
 * 调用系统相机
 */
private void takePhoto() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        if (Build.VERSION.SDK_INT > 23) {
            /**
             *Android 7.0以上的方式*
             */
            mStorageManager = this.getSystemService(StorageManager.class);
            StorageVolume storageVolume = mStorageManager.getPrimaryStorageVolume();
            Intent intent = storageVolume.createAccessIntent(Environment.DIRECTORY_DOWNLOADS);
            startActivityForResult(intent, REQUEST_CODE_GRAINT_URI);
        }
    } else {
        Toast.makeText(this, "sdcard不存在", Toast.LENGTH_SHORT).show();
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager) Intent(android.content.Intent)

Example 58 with StorageVolume

use of android.os.storage.StorageVolume in project android_packages_apps_Camera by CyanogenMod.

the class CameraSettings method buildStorage.

private void buildStorage(PreferenceGroup group, ListPreference storage) {
    StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
    StorageVolume[] volumes = sm.getVolumeList();
    String[] entries = new String[volumes.length];
    String[] entryValues = new String[volumes.length];
    int primary = 0;
    if (volumes.length < 2) {
        // No need for storage setting  264
        removePreference(group, storage.getKey());
        return;
    }
    for (int i = 0; i < volumes.length; i++) {
        StorageVolume v = volumes[i];
        entries[i] = v.getDescription(mContext);
        entryValues[i] = v.getPath();
        if (v.isPrimary()) {
            primary = i;
        }
    }
    storage.setEntries(entries);
    storage.setEntryValues(entryValues);
    // Filter saved invalid value
    if (storage.findIndexOfValue(storage.getValue()) < 0) {
        // Default to the primary storage
        storage.setValueIndex(primary);
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager)

Example 59 with StorageVolume

use of android.os.storage.StorageVolume in project Signal-Android by WhisperSystems.

the class StorageUtil method getDisplayPath.

@RequiresApi(24)
@NonNull
public static String getDisplayPath(@NonNull Context context, @NonNull Uri uri) {
    String lastPathSegment = Objects.requireNonNull(uri.getLastPathSegment());
    String backupVolume = lastPathSegment.replaceFirst(":.*", "");
    String backupName = lastPathSegment.replaceFirst(".*:", "");
    StorageManager storageManager = ServiceUtil.getStorageManager(context);
    List<StorageVolume> storageVolumes = storageManager.getStorageVolumes();
    StorageVolume storageVolume = null;
    for (StorageVolume volume : storageVolumes) {
        if (Objects.equals(volume.getUuid(), backupVolume)) {
            storageVolume = volume;
            break;
        }
    }
    if (storageVolume == null) {
        return backupName;
    } else {
        return context.getString(R.string.StorageUtil__s_s, storageVolume.getDescription(context), backupName);
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager) NonNull(androidx.annotation.NonNull) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

StorageVolume (android.os.storage.StorageVolume)59 StorageManager (android.os.storage.StorageManager)18 File (java.io.File)16 Intent (android.content.Intent)14 VolumeInfo (android.os.storage.VolumeInfo)10 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6 UserHandle (android.os.UserHandle)6 Parcelable (android.os.Parcelable)5 VolumeRecord (android.os.storage.VolumeRecord)5 ArraySet (android.util.ArraySet)5 AtomicFile (android.util.AtomicFile)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IOException (java.io.IOException)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 HandlerThread (android.os.HandlerThread)2 RemoteException (android.os.RemoteException)2 IMountService (android.os.storage.IMountService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2