android 设备获取本机CPU,RAM,ROM等信息

private String getHandSetInfo() {
    Display dis = this.getWindowManager().getDefaultDisplay();
    double ran = getAvailMemory(this) / 1000;
    BigDecimal c = new BigDecimal(ran);
    double d = c.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
    String handSetInfo = "产品型号:" + android.os.Build.MODEL
            + "\n安卓版本:" + android.os.Build.VERSION.RELEASE
            + "\n内存:" + android.os.Build.PRODUCT
            + "\n存储:" + d + "GB"
            + "\nCPU:" + android.os.Build.CPU_ABI + "," + getMaxCpuFreq() + "GHz*" + getNumberOfCPUCores()
            + "\n分辨率:" + dis.getWidth() + "×" + dis.getHeight()
            + "\n版本显示:" + android.os.Build.DISPLAY
            + "\n基带版本:" + getBaseband_Ver()
            + "\n系统定制商:" + android.os.Build.BRAND
            + "\n设备参数:" + android.os.Build.DEVICE
            + "\n开发代号:" + android.os.Build.VERSION.CODENAME
            + "\nIMEI:" + getIMEI(this)
            + "\nSDK版本号:" + android.os.Build.VERSION.SDK_INT
            + "\n硬件类型:" + android.os.Build.HARDWARE
            + "\n主机:" + android.os.Build.HOST
            + "\n生产ID:" + android.os.Build.ID
            + "\nROM制造商:" + android.os.Build.MANUFACTURER // 这行返回的是rom定制商的名称
            +"\napp版本:"+getVersion()
            ;
    return handSetInfo;

}

/**
 *
 * 当前应用的版本号
 *
 */
public String getVersion() {
    try {
        PackageManager manager = this.getPackageManager();
        PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
        String version = info.versionName;
        return version;
    } catch (Exception e) {
        e.printStackTrace();
        return "没找到";
    }
}

/**
 * 获取android当前可用内存大小
 */
private double getAvailMemory(Context context) {

    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    return (double) mi.totalMem / (1024 * 1024);
}

/**
 * CPU核数
 */
public static int getNumberOfCPUCores() {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        return 1;
    }
    int cores;
    try {
        cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
    } catch (SecurityException e) {
        cores = 9;
    } catch (NullPointerException e) {
        cores = 9;
    }
    return cores;
}

private static final FileFilter CPU_FILTER = new FileFilter() {
    @Override
    public boolean accept(File pathname) {
        String path = pathname.getName();
        if (path.startsWith("cpu")) {
            for (int i = 3; i < path.length(); i++) {
                if (path.charAt(i) < '0' || path.charAt(i) > '9') {
                    return false;
                }
            }
            return true;
        }
        return false;
    }
};
/**
 * 获取设备基带版本
 */
public static String getBaseband_Ver() {
    String Version = "";
    try {
        Class cl = Class.forName("android.os.SystemProperties");
        Object invoker = cl.newInstance();
        Method m = cl.getMethod("get", new Class[]{String.class, String.class});
        Object result = m.invoke(invoker, new Object[]{"gsm.version.baseband", "no message"});
        Version = (String) result;
    } catch (Exception e) {
    }
    return Version;
}

/**
 * CPU最大运行频率
 */
public static double getMaxCpuFreq() {
    String result = "";
    ProcessBuilder cmd;
    try {
        String[] args = {"/system/bin/cat",
                "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"};
        cmd = new ProcessBuilder(args);
        Process process = cmd.start();
        InputStream in = process.getInputStream();
        byte[] re = new byte[24];
        while (in.read(re) != -1) {
            result = result + new String(re);
        }
        in.close();
    } catch (IOException ex) {
        ex.printStackTrace();
        result = "N/A";
    }
    double a = Integer.parseInt(result.trim());
    double b = a / 1000000;
    BigDecimal c = new BigDecimal(b);
    double d = c.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
    return d;
}

/**
 * 获取手机IMEI号
 */
public static String getIMEI(Context context) {

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return "";
    }
    String imei = tm.getDeviceId();
    return imei;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值