Obtain basic information about android phones and basic information about android phones.
Java code
- /**
- * Get the current available memory size of android
- */
- Private String getAvailMemory () {// gets the current available memory size of android
- ActivityManager am = (ActivityManager) getSystemService (Context. ACTIVITY_SERVICE );
- MemoryInfo mi = new MemoryInfo ();
- Am. getMemoryInfo (mi );
- // Mi. availMem; available memory of the current system
- Return Formatter. formatFileSize (getBaseContext (), mi. availMem); // normalize the obtained memory size
- }
- /**
- * Obtain the total system memory.
- */
- Private String getTotalMemory (){
- String str1 = "/proc/meminfo"; // system memory information file
- String str2;
- String [] arrayOfString;
- Long initial_memory = 0;
- Try {
- FileReader localFileReader = new FileReader (str1 );
- BufferedReader localBufferedReader = new BufferedReader (
- LocalFileReader, 8192 );
- Str2 = localBufferedReader. readLine (); // read the first line of meminfo, total system memory size
- ArrayOfString = str2.split ("\ s + ");
- For (String num: arrayOfString ){
- Log. I (str2, num + "\ t ");
- }
- Initial_memory = Integer. valueOf (arrayOfString [1]). intValue () * 1024; // obtain the total system memory, measured in KB, multiplied by 1024 to Byte
- LocalBufferedReader. close ();
- } Catch (IOException e ){
- }
- Return Formatter. formatFileSize (getBaseContext (), initial_memory); // convert Byte to KB or MB, and normalize the memory size.
- }
- /**
- * Screen width and height
- * @ Return
- */
- Public String getHeightAndWidth (){
- Int width = getWindowManager (). getDefaultDisplay (). getWidth ();
- Int heigth = getWindowManager (). getdefadisplay display (). getHeight ();
- String str = width + "" + heigth + "";
- Return str;
- }
- /**
- * Obtain the IMEI number, IESI number, and mobile phone model.
- */
- Private void getInfo (){
- TelephonyManager mTm = (TelephonyManager) this. getSystemService (TELEPHONY_SERVICE );
- String imei = mTm. getDeviceId ();
- String imsi = mTm. getSubscriberId ();
- String mtype = android. OS. Build. MODEL; // Mobile Phone MODEL
- String mtyb = android. OS. Build. BRAND; // mobile phone BRAND
- String numer = mTm. getLine1Number (); // mobile phone number, which is available or unavailable
- Log. I ("text", "Mobile Phone IMEI number:" + imei + "Mobile Phone IESI number:" + imsi + "Mobile Phone model:" + mtype + "mobile phone brand: "+ mtyb +" mobile phone number "+ numer );
- }
- /**
- *. Obtain the MAC address of the mobile phone.
- * The mac address can be obtained only when wifi is enabled on the mobile phone.
- */
- Private String getMacAddress (){
- String result = "";
- WifiManager wifiManager = (WifiManager) getSystemService (Context. WIFI_SERVICE );
- WifiInfo wifiInfo = wifiManager. getConnectionInfo ();
- Result = wifiInfo. getMacAddress ();
- Log. I ("text", "Mobile macAdd:" + result );
- Return result;
- }
- /**
- * Mobile Phone CPU Information
- */
- Private String [] getCpuInfo (){
- String str1 = "/proc/cpuinfo ";
- String str2 = "";
- String [] cpuInfo = {"", ""}; // 1-cpu model // 2-cpu frequency
- 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 ){
- }
- Log. I ("text", "cpuinfo:" + cpuInfo [0] + "" + cpuInfo [1]);
- Return cpuInfo;
- }
Java code
- <! -- Obtain mac address permissions -->
- <Uses-permission android: name = "android. permission. ACCESS_WIFI_STATE"/>
- <! -- Get mobile phone information -->
- <Uses-permission android: name = "android. permission. READ_PHONE_STATE"/>