android.app.usage.StorageStatsManager#getTotalBytes ( )源码实例Demo

下面列出了android.app.usage.StorageStatsManager#getTotalBytes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MobileInfo   文件: MemoryInfo.java
/**
 * 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;
    }
}
 
源代码2 项目: AndroidDemo   文件: StorageActivity.java
/**
 * 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;
    }
}
 
源代码3 项目: AndroidDemo   文件: StorageQueryUtil.java
/**
 * 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;
    }
}
 
 同类方法