Go to: Get some information about the Android mobile phone

Source: Internet
Author: User
Tags android games

Come and have a look at the Android games!

1. Obtain the app information installed on your mobile phone (excluding the app information that comes with the system ):

Java code:

 1 private String getAllApp() {  
2 String result = "";
3 List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
4 for (PackageInfo i : packages) {
5 if ((i.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6 result += i.applicationInfo.loadLabel(getPackageManager()).toString() + ",";
7 }
8 }
9 return result.substring(0, result.length() - 1);
10 }

Return the app1, app2, app3,..., and appn separated by "," in the form of a string. Of course, you can also get the package name, icon, and so on.

 

2. Get the available memory and total memory of the mobile phone:

Java code:

 1     private String[] getTotalMemory() {  
2 String[] result = {"",""}; //1-total 2-avail
3 ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
4 mActivityManager.getMemoryInfo(mi);
5 long mTotalMem = 0;
6 long mAvailMem = mi.availMem;
7 String str1 = "/proc/meminfo";
8 String str2;
9 String[] arrayOfString;
10 try {
11 FileReader localFileReader = new FileReader(str1);
12 BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
13 str2 = localBufferedReader.readLine();
14 arrayOfString = str2.split("\\s+");
15 mTotalMem = Integer.valueOf(arrayOfString[1]).intValue() * 1024;
16 localBufferedReader.close();
17 } catch (IOException e) {
18 e.printStackTrace();
19 }
20 result[0] = Formatter.formatFileSize(this, mTotalMem);
21 result[1] = Formatter.formatFileSize(this, mAvailMem);
22 Log.i(TAG, "meminfo total:" + result[0] + " used:" + result[1]);
23 return result;
24 }

The memory information of the mobile phone is mainly in the/proc/meminfo file. The first line is the total memory, and the remaining memory can be obtained through ActivityManager. MemoryInfo.

 

3. Mobile phone CPU Information

Java code:

1 private String [] getCpuInfo (){
2 String str1 = "/proc/cpuinfo ";
3 String str2 = "";
4 String [] cpuInfo = {"", ""}; // 1-cpu model // 2-cpu frequency
5 String [] arrayOfString;
6 try {
7 FileReader fr = new FileReader (str1 );
8 BufferedReader localBufferedReader = new BufferedReader (fr, 8192 );
9 str2 = localBufferedReader. readLine ();
10 arrayOfString = str2.split ("\ s + ");
11 for (int I = 2; I <arrayOfString. length; I ++ ){
12 cpuInfo [0] = cpuInfo [0] + arrayOfString [I] + "";
13}
14 str2 = localBufferedReader. readLine ();
15 arrayOfString = str2.split ("\ s + ");
16 cpuInfo [1] + = arrayOfString [2];
17 localBufferedReader. close ();
18} catch (IOException e ){
19}
20 Log. I (TAG, "cpuinfo:" + cpuInfo [0] + "" + cpuInfo [1]);
21 return cpuInfo;
22}

Similar to the memory information, the cpu information can be obtained by reading the/proc/cpuinfo file, where the first act is the cpu model and the second act is the cpu frequency.

 

4. Obtain the MAC address of the mobile phone:

Java code:

1     private String getMacAddress(){  
2 String result = "";
3 WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
4 WifiInfo wifiInfo = wifiManager.getConnectionInfo();
5 result = wifiInfo.getMacAddress();
6 Log.i(TAG, "macAdd:" + result);
7 return result;
8 }

The MAC address is relatively easy and can be obtained directly through WifiManager.

 

4. IMEI, IESI, and mobile phone model:

Java code:

1 private void getInfo (){
2 TelephonyManager mTm = (TelephonyManager) getSystemService (TELEPHONY_SERVICE );
3 String imei = mTm. getDeviceId ();
4 String imsi = mTm. getSubscriberId ();
5 String mtype = android. OS. Build. MODEL; // Mobile Phone MODEL
6 String numer = mTm. getLine1Number (); // mobile phone number, which is available or unavailable
7}

 

5. Get the screen height of the mobile phone:

Java code:

1 private void getWeithAndHeight (){
2 // This method cannot be used in the service,
3 DisplayMetrics dm = new DisplayMetrics ();
4 getWindowManager (). getDefaultDisplay (). getMetrics (dm );
5 String width = dm. widthPixels; // width
6 String height = dm. heightPixels; // high
7
8 // the height and width can also be obtained in the service
9 WindowManager mWindowManager = (WindowManager) getSystemService (Context. WINDOW_SERVICE );
10 width = mWindowManager. getDefaultDisplay (). getWidth ();
11 height = mWindowManager. getDefaultDisplay (). getHeight ();
12}

Address: http://www.cnblogs.com/ayan/archive/2011/12/29/2306824.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.