查看Android不同版本API的地址為: https://developer.android.google.cn/reference/packages 選擇對(duì)應(yīng)的Android版本,查看對(duì)應(yīng)的Android模塊,即可查找到對(duì)應(yīng)版本的API參考文檔: //計(jì)算EMMC和DDR TextView txEmmcTotal = v.findViewById(R.id.txEmmcTotal); TextView txDDRTotal = v.findViewById(R.id.txDDRTotal); TextView txEmmcRest = v.findViewById(R.id.txEmmcRest); TextView txDDRRest = v.findViewById(R.id.txDDRRest); ActivityManager activityManager = (ActivityManager) requireActivity().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); float totalMemory = (float)memoryInfo.totalMem/(1024 * 1024 * 1024); Log.e(TAG, "setVersionInfo: totalMemory= "+ String.format("%.2f",totalMemory) + 'G'); txEmmcTotal.setText(String.format("%.2f",totalMemory) + "GB"); float availMemory = (float)memoryInfo.availMem/(1024*1024*1024); Log.e(TAG, "setVersionInfo: availMemory= "+ String.format("%.2f",availMemory) + "GB"); txEmmcRest.setText(String.format("%.2f",availMemory) + "GB"); //系統(tǒng)文件大小 StatFs stat = new StatFs(Environment.getRootDirectory().getAbsolutePath()); long systemSize = stat.getTotalBytes(); Log.e(TAG, "setVersionInfo: systemSize= "+ String.format("%.2f",systemSize/(1024f * 1024 * 1024)) + "GB"); txDDRTotal.setText(String.format("%.2f",systemSize/(1024f * 1024 * 1024)) + "GB"); long availableSize = stat.getAvailableBytes(); Log.e(TAG, "setVersionInfo: availableSize="+ String.format("%.2f",availableSize/(1024f * 1024 * 1024)) + "GB"); txDDRRest.setText(String.format("%.2f",availableSize/(1024f * 1024 * 1024)) + "GB"); //內(nèi)部sd存儲(chǔ)空間大小 // StatFs stat1 = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); // Log.e(TAG, "setVersionInfo: getExternalStorageDirectory="+Environment.getExternalStorageDirectory().getAbsolutePath()); // long internal_sd_totalBlocks = stat1.getBlockCountLong();// 獲取block數(shù)量 // long internal_sd_blockSize = stat1.getBlockSizeLong(); // long internal_sd_totalSize = internal_sd_blockSize * internal_sd_totalBlocks; // Log.e(TAG, "setVersionInfo: internal_sd_totalSize="+ String.format("%.2f",internal_sd_totalSize/(1024f * 1024 * 1024)) + "GB"); |
|