获取 Android 设备 屏幕,内存,存储大小

获取内存总大小

ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
am.getMemoryInfo(info);
info.totalMem;

获取存储总大小

StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
try {
    return stats.getTotalBytes(StorageManager.UUID_DEFAULT);
} catch (IOException e) {
    e.printStackTrace();
}

获取屏幕大小

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
metrics.widthPixels
metrics.heightPixels

你可能感兴趣的:(android之路,android)