码迷,mamicode.com
首页 > 移动开发 > 详细

获取Android手机基本信息

时间:2015-02-10 21:38:46      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

  1 /** 
  2  * 获取android当前可用内存大小  
  3  */  
  4  private String getAvailMemory() {// 获取android当前可用内存大小     
  5         
  6         ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);    
  7         MemoryInfo mi = new MemoryInfo();    
  8         am.getMemoryInfo(mi);    
  9         //mi.availMem; 当前系统的可用内存     
 10     
 11         return Formatter.formatFileSize(getBaseContext(), mi.availMem);// 将获取的内存大小规格化     
 12     }    
 13   
 14 /** 
 15  * 获得系统总内存 
 16  */  
 17 private String getTotalMemory() {  
 18     String str1 = "/proc/meminfo";// 系统内存信息文件   
 19     String str2;  
 20     String[] arrayOfString;  
 21     long initial_memory = 0;  
 22   
 23     try {  
 24     FileReader localFileReader = new FileReader(str1);  
 25     BufferedReader localBufferedReader = new BufferedReader(  
 26     localFileReader, 8192);  
 27     str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小   
 28   
 29     arrayOfString = str2.split("\\s+");  
 30     for (String num : arrayOfString) {  
 31     Log.i(str2, num + "\t");  
 32     }  
 33   
 34     initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte   
 35     localBufferedReader.close();  
 36   
 37     } catch (IOException e) {  
 38     }  
 39     return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化   
 40     }  
 41   
 42 /** 
 43  * 获得手机屏幕宽高 
 44  * @return 
 45  */  
 46 public String getHeightAndWidth(){  
 47     int width=getWindowManager().getDefaultDisplay().getWidth();  
 48     int heigth=getWindowManager().getDefaultDisplay().getHeight();  
 49     String str=width+""+heigth+"";  
 50     return str;  
 51 }  
 52 /** 
 53  * 获取IMEI号,IESI号,手机型号 
 54  */  
 55 private void getInfo() {  
 56       TelephonyManager mTm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);  
 57        String imei = mTm.getDeviceId();  
 58        String imsi = mTm.getSubscriberId();  
 59        String mtype = android.os.Build.MODEL; // 手机型号  
 60        String mtyb= android.os.Build.BRAND;//手机品牌  
 61        String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得  
 62        Log.i("text", "手机IMEI号:"+imei+"手机IESI号:"+imsi+"手机型号:"+mtype+"手机品牌:"+mtyb+"手机号码"+numer);  
 63    }  
 64 /** 
 65  * .获取手机MAC地址 
 66  * 只有手机开启wifi才能获取到mac地址 
 67  */  
 68 private String getMacAddress(){  
 69        String result = "";  
 70        WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);  
 71        WifiInfo wifiInfo = wifiManager.getConnectionInfo();  
 72        result = wifiInfo.getMacAddress();  
 73        Log.i("text", "手机macAdd:" + result);  
 74        return result;  
 75    }  
 76 /** 
 77  * 手机CPU信息 
 78  */  
 79 private String[] getCpuInfo() {  
 80        String str1 = "/proc/cpuinfo";  
 81        String str2 = "";  
 82        String[] cpuInfo = {"", ""};  //1-cpu型号  //2-cpu频率  
 83        String[] arrayOfString;  
 84        try {  
 85            FileReader fr = new FileReader(str1);  
 86            BufferedReader localBufferedReader = new BufferedReader(fr, 8192);  
 87            str2 = localBufferedReader.readLine();  
 88            arrayOfString = str2.split("\\s+");  
 89            for (int i = 2; i < arrayOfString.length; i++) {  
 90                cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";  
 91            }  
 92            str2 = localBufferedReader.readLine();  
 93            arrayOfString = str2.split("\\s+");  
 94            cpuInfo[1] += arrayOfString[2];  
 95            localBufferedReader.close();  
 96        } catch (IOException e) {  
 97        }  
 98        Log.i("text", "cpuinfo:" + cpuInfo[0] + " " + cpuInfo[1]);  
 99        return cpuInfo;  
100    }
1 <!--         获取mac地址权限 -->  
2     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />    
3 <!--     获取手机信息权限 -->  
4     <uses-permission android:name="android.permission.READ_PHONE_STATE" />  

 

获取Android手机基本信息

标签:

原文地址:http://www.cnblogs.com/cycst/p/4284789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!