解决方案:
1. 获取Ram大小
//RAM内存大小, 返回1GB/2GB/3GB/4GB/8G/16G
public static String getTotalRam(){
String path = "/proc/meminfo";
String ramMemorySize = null;
int totalRam = 0 ;
try{
FileReader fileReader = new FileReader(path);
BufferedReader br = new BufferedReader(fileReader, 4096);
ramMemorySize = br.readLine().split("\\s+")[1];
br.close();
}catch (Exception e){
e.printStackTrace();
}
if(ramMemorySize != null){
totalRam = (int)Math.ceil((new Float(Float.valueOf(ramMemorySize) / (1024 * 1024)).doubleValue()));
}
return totalRam + "GB";
}
2. 获取Rom大小
//ROM内存大小,返回 64G/128G/256G/512G
private static String getTotalRom() {
File dataDir = Environment.getDataDirectory();
StatFs stat = new StatFs(dataDir.getPath());
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
long size = totalBlocks * blockSize;
long GB = 1024 * 1024 * 1024;
final long[] deviceRomMemoryMap = {2*GB, 4*GB, 8*GB, 16*GB, 32*GB, 64*GB, 128*GB, 256*GB, 512*GB, 1024*GB, 2048*GB};
String[] displayRomSize = {"2GB","4GB","8GB","16GB","32GB","64GB","128GB","256GB","512GB","1024GB","2048GB"};
int i;
for(i = 0 ; i < deviceRomMemoryMap.length; i++) {
if(size <= deviceRomMemoryMap[i]) {
break;
}
if(i == deviceRomMemoryMap.length) {
i--;
}
}
return displayRomSize[i];
}
————————————————