Android 获取手机信息

  1. /** 
  2.      * 获取手机信息 
  3.      */  
  4.     public void getPhoneInfo()  
  5.     {  
  6.         TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);  
  7.         String mtyb = android.os.Build.BRAND;// 手机品牌  
  8.         String mtype = android.os.Build.MODEL; // 手机型号  
  9.         String imei = tm.getDeviceId();  
  10.         String imsi = tm.getSubscriberId();  
  11.         String numer = tm.getLine1Number(); // 手机号码  
  12.         String serviceName = tm.getSimOperatorName(); // 运营商  
  13.         tvPhoneInfo.setText("品牌: " + mtyb + "\n" + "型号: " + mtype + "\n" + "版本: Android " + android.os.Build.VERSION.RELEASE + "\n" + "IMEI: " + imei  
  14.                 + "\n" + "IMSI: " + imsi + "\n" + "手机号码: " + numer + "\n" + "运营商: " + serviceName + "\n");  
  15.     }  


  1. /** 
  2.      * 获取手机内存大小 
  3.      *  
  4.      * @return 
  5.      */  
  6.     private String getTotalMemory()  
  7.     {  
  8.         String str1 = "/proc/meminfo";// 系统内存信息文件  
  9.         String str2;  
  10.         String[] arrayOfString;  
  11.         long initial_memory = 0;  
  12.         try  
  13.         {  
  14.             FileReader localFileReader = new FileReader(str1);  
  15.             BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);  
  16.             str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小  
  17.   
  18.             arrayOfString = str2.split("\\s+");  
  19.             for (String num : arrayOfString)  
  20.             {  
  21.                 Log.i(str2, num + "\t");  
  22.             }  
  23.   
  24.             initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte  
  25.             localBufferedReader.close();  
  26.   
  27.         }  
  28.         catch (IOException e)  
  29.         {  
  30.         }  
  31.         return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化  
  32.     }  

  1. /** 
  2.  * 获取当前可用内存大小 
  3.  *  
  4.  * @return 
  5.  */  
  6. private String getAvailMemory()  
  7. {  
  8.     ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);  
  9.     MemoryInfo mi = new MemoryInfo();  
  10.     am.getMemoryInfo(mi);  
  11.     return Formatter.formatFileSize(getBaseContext(), mi.availMem);  
  12. }  


  1. /** 
  2.      * 获取手机CPU信息 
  3.      *  
  4.      * @return 
  5.      */  
  6.     public String[] getCpuInfo()  
  7.     {  
  8.         String str1 = "/proc/cpuinfo";  
  9.         String str2 = "";  
  10.         String[] cpuInfo = { """" };  
  11.         String[] arrayOfString;  
  12.         try  
  13.         {  
  14.             FileReader fr = new FileReader(str1);  
  15.             BufferedReader localBufferedReader = new BufferedReader(fr, 8192);  
  16.             str2 = localBufferedReader.readLine();  
  17.             arrayOfString = str2.split("\\s+");  
  18.             for (int i = 2; i < arrayOfString.length; i++)  
  19.             {  
  20.                 cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";  
  21.             }  
  22.             str2 = localBufferedReader.readLine();  
  23.             arrayOfString = str2.split("\\s+");  
  24.             cpuInfo[1] += arrayOfString[2];  
  25.             localBufferedReader.close();  
  26.         }  
  27.         catch (IOException e)  
  28.         {  
  29.         }  
  30.         tvHardwareInfo.append("CPU型号 " + cpuInfo[0] + "\n" + "CPU频率: " + cpuInfo[1] + "\n");  
  31.         return cpuInfo;  
  32.     }  


  1. /** 
  2.  * 获取CPU核心数 
  3.  *  
  4.  * @return 
  5.  */  
  6. private int getNumCores()  
  7. {  
  8.     // Private Class to display only CPU devices in the directory listing  
  9.     class CpuFilter implements FileFilter  
  10.     {  
  11.         @Override  
  12.         public boolean accept(File pathname)  
  13.         {  
  14.             // Check if filename is "cpu", followed by a single digit number  
  15.             if (Pattern.matches("cpu[0-9]", pathname.getName()))  
  16.             {  
  17.                 return true;  
  18.             }  
  19.             return false;  
  20.         }  
  21.     }  
  22.   
  23.     try  
  24.     {  
  25.         // Get directory containing CPU info  
  26.         File dir = new File("/sys/devices/system/cpu/");  
  27.         // Filter to only list the devices we care about  
  28.         File[] files = dir.listFiles(new CpuFilter());  
  29.         // Return the number of cores (virtual CPU devices)  
  30.         return files.length;  
  31.     }  
  32.     catch (Exception e)  
  33.     {  
  34.         e.printStackTrace();  
  35.         // Default to return 1 core  
  36.         return 1;  
  37.     }  

来源:http://blog.csdn.net/vestigge/article/details/8691894
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值