是否有功能或命令来获取Android设备的基本设备配置?像RAM大小,操作系统版本,处理器核心数量等。
答案 0 :(得分:4)
您可以获取所有设备信息。希望得到帮助。
获取设备的CPU核心
/**
* Gets the number of cores available in this device, across all processors.
* Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
* @return The number of cores, or 1 if failed to get result
*/
private int getNumCores() {
//Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
//Check if filename is "cpu", followed by a single digit number
if(Pattern.matches("cpu[0-9]+", pathname.getName())) {
return true;
}
return false;
}
}
try {
//Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
//Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
//Return the number of cores (virtual CPU devices)
return files.length;
} catch(Exception e) {
//Default to return 1 core
return 1;
}
}
获取设备的总RAM
public static String getTotalRAM() {
RandomAccessFile reader = null;
String load = null;
try {
reader = new RandomAccessFile("/proc/meminfo", "r");
load = reader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
// Streams.close(reader);
}
return load;
}
设备的其他信息
String _OSVERSION = System.getProperty("os.version");
String _RELEASE = android.os.Build.VERSION.RELEASE;
String _DEVICE = android.os.Build.DEVICE;
String _MODEL = android.os.Build.MODEL;
String _PRODUCT = android.os.Build.PRODUCT;
String _BRAND = android.os.Build.BRAND;
String _DISPLAY = android.os.Build.DISPLAY;
String _CPU_ABI = android.os.Build.CPU_ABI;
String _CPU_ABI2 = android.os.Build.CPU_ABI2;
String _UNKNOWN = android.os.Build.UNKNOWN;
String _HARDWARE = android.os.Build.HARDWARE;
String _ID = android.os.Build.ID;
String _MANUFACTURER = android.os.Build.MANUFACTURER;
String _SERIAL = android.os.Build.SERIAL;
String _USER = android.os.Build.USER;
String _HOST = android.os.Build.HOST;
答案 1 :(得分:2)
您可以从/ proc / cpuinfo文件中获取所需的大部分信息。以下是有关如何加载和解析该文件的教程:How to get Cpu Information on android
有关RAM的信息可以从/ proc / meminfo文件中获取
答案 2 :(得分:1)
查看android.os.Build课程。
android.os.Build.HARDWARE
android.os.Build.DEVICE
android.os.Build.MODEL
android.os.Build.PRODUCT
android.os.Build.BOARD
android.os.Build.DISPLAY
等...
要获取操作系统版本号,您可以尝试
System.getProperty("os.version");
答案 3 :(得分:1)
您可以查看android.os.Build
以确定手机品牌和型号。从那里开始查找基于品牌和型号的手机规格。