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());
}
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();
}
}
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);
}
}
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);
}
}
Aggregations