android获取手机基本信息

有时候我们需要获取手机设备的一下信息就可以使用如下方法:

//得到当前手机设备名称
private String getPhoneInfo() {
   StringBuffer phoneI签: " + android.os.Build.TAGS) ;
   phoneInfo.append("\n手机型号: " + android.os.Build.MODEL);
   phoneInfo.append("\nSDK版本: " + android.os.Build.VERSION.SDK);
   phoneInfo.append ("\n系统版本: " + android.os.Build.VERSION.RELEASE);
   phoneInfo.append ("\n设备驱动: " + android.os.Build.DEVICE);
   phoneInfo.append("\n版本号: " + android.os.Build.DISPLAY);
   phoneInfo.append("\n品牌: " + android.os.Build.BRAND);
   phoneInfo.append("\n主板: " + android.os.Build.BOARD);
   phoneInfo.append("\n指纹: " + android.os.Build.FINGERPRINT);
   phoneInfo.append("\nID: " + android.os.Build.ID);
   phoneInfo.append("\n制造商: " + android.os.Build.MANUFACTURER);
   phoneInfo.append("\n用户组: " + android.os.Build.USER);

   return phoneInfo.toString();
}

然后直接调用这个方法去获取即可。



同时不要忘记:

在manifest.xml文件中要添加 <uses-permission Android:name="android.permission.READ_PHONE_STATE" />权限


自己也整理了一下:

public class DeviceInfoUtil {

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

        ActivityManager am = (ActivityManager)BaseApplication.getContext().getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
        am.getMemoryInfo(mi);
        //mi.availMem; 当前系统的可用内存

        return Formatter.formatFileSize(BaseApplication.getContext(), mi.availMem);// 将获取的内存大小规格化
    }

    /**
     * 获得系统总内存
     */
    private String getTotalMemory() {
        String str1 = "/proc/meminfo";// 系统内存信息文件
        String str2;
        String[] arrayOfString;
        long initial_memory = 0;

        try {
            FileReader localFileReader = new FileReader(str1);
            BufferedReader localBufferedReader = new BufferedReader(
                    localFileReader, 8192);
            str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小

            arrayOfString = str2.split("\\s+");
            for (String num : arrayOfString) {
                LoggerUtil.i(str2, num + "\t");
            }

            initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte
            localBufferedReader.close();

        } catch (IOException e) {
        }
        return Formatter.formatFileSize(BaseApplication.getContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化
    }

    /**
     * 获取IMEI号,IESI号,手机型号
     */
    public static void getInfo() {
        TelephonyManager mTm = (TelephonyManager)BaseApplication.getContext().getSystemService(BaseApplication.getContext().TELEPHONY_SERVICE);
        String imei = mTm.getDeviceId();//IMEI 国际移动设备识别码
        String imsi = mTm.getSubscriberId();//IMSI 国际移动用户识别码
        String mtype = android.os.Build.MODEL; // 手机型号
        String mtyb= android.os.Build.BRAND;//手机品牌
        String release=android.os.Build.VERSION.RELEASE;//系统版本
        String display=android.os.Build.DISPLAY;//版本号
        String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得
       mtype=mtype.replace(" ","");//去掉空格
       LoggerUtil.i("DeviceInfo", "手机IMEI号:"+imei
                +"\n手机IMSI号:" +imsi
                +"\n手机型号:"+mtype
                +"\n系统版本:"+release
                +"\n版本号:"+display
                +"\n手机品牌:"+mtyb
                +"\n手机号码:"+numer);

        
       
 }
    /**
     * .获取手机MAC地址
     * 只有手机开启wifi才能获取到mac地址
     */
    private String getMacAddress(){
        String result = "";
        WifiManager wifiManager = (WifiManager) BaseApplication.getContext().getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        result = wifiInfo.getMacAddress();
        LoggerUtil.i("text", "手机macAdd:" + result);
        return result;
    }
    /**
     * 手机CPU信息
     */
    private String[] getCpuInfo() {
        String str1 = "/proc/cpuinfo";
        String str2 = "";
        String[] cpuInfo = {"", ""};  //1-cpu型号  //2-cpu频率
        String[] arrayOfString;
        try {
            FileReader fr = new FileReader(str1);
            BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
            str2 = localBufferedReader.readLine();
            arrayOfString = str2.split("\\s+");
            for (int i = 2; i < arrayOfString.length; i++) {
                cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";
            }
            str2 = localBufferedReader.readLine();
            arrayOfString = str2.split("\\s+");
            cpuInfo[1] += arrayOfString[2];
            localBufferedReader.close();
        } catch (IOException e) {
        }
        LoggerUtil.i("text", "cpuinfo:" + cpuInfo[0] + " " + cpuInfo[1]);
        return cpuInfo;
    }
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值