Java Code Examples for android.app.usage.StorageStatsManager#getTotalBytes()

The following examples show how to use android.app.usage.StorageStatsManager#getTotalBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
/**
 * API 26 android O
 * 获取总共容量大小,包括系统大小
 */
@SuppressLint("NewApi")
public static long getTotalSize(Context context, String fsUuid) {
    try {
        UUID id;
        if (fsUuid == null) {
            id = StorageManager.UUID_DEFAULT;
        } else {
            id = UUID.fromString(fsUuid);
        }
        StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
        return stats.getTotalBytes(id);
    } catch (NoSuchFieldError | NoClassDefFoundError | NullPointerException | IOException e) {
        e.printStackTrace();
        return -1;
    }
}
 
Example 2
Source File: StorageActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
/**
 * API 26 android O
 * 获取总共容量大小,包括系统大小
 */
@RequiresApi(api = 26)
public long getTotalSize(String fsUuid) {
    try {
        UUID id;
        if (fsUuid == null) {
            id = StorageManager.UUID_DEFAULT;
        } else {
            id = UUID.fromString(fsUuid);
        }
        StorageStatsManager stats = (StorageStatsManager) getSystemService(Context.STORAGE_STATS_SERVICE);
        return stats.getTotalBytes(id);
    } catch (NoSuchFieldError | NoClassDefFoundError | NullPointerException | IOException e) {
        e.printStackTrace();
        ToastUtils.show(this, "获取存储大小失败");
        return -1;
    }
}
 
Example 3
Source File: StorageQueryUtil.java    From AndroidDemo with MIT License 6 votes vote down vote up
/**
 * API 26 android O
 * 获取总共容量大小,包括系统大小
 */
@RequiresApi(Build.VERSION_CODES.O)
public static long getTotalSize(Context context, String fsUuid) {
    try {
        UUID id;
        if (fsUuid == null) {
            id = StorageManager.UUID_DEFAULT;
        } else {
            id = UUID.fromString(fsUuid);
        }
        StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
        return stats.getTotalBytes(id);
    } catch (NoSuchFieldError | NoClassDefFoundError | NullPointerException | IOException e) {
        e.printStackTrace();
        return -1;
    }
}