1.获取手机安装的应用信息(排除系统自带):
private String getAllApp() {以字符串的形式返回应用的名字app1,app2,app3,......,appn中间的以","分开。当然还可以得到包名,icon图标,等等 。
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 }
2.获取手机可用内存和总内存:
Java代码:
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 }
手机的内存信息主要在/proc/meminfo文件中,其中第一行就是总内存,而剩余内存可通过 ActivityManager.MemoryInfo得到 。
3.手机CPU信息
Java代码:
1 private String[] getCpuInfo() {
2 String str1 = "/proc/cpuinfo";
3 String str2 = "";
4 String[] cpuInfo = {"", ""}; //1-cpu型号 //2-cpu频率
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 }
和内存信息同理,cpu信息可通过读取/proc/cpuinfo文件来得到,其中第一行为cpu型号,第二行为cpu频率。
4.获取手机MAC地址:
Java代码:
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 }
MAC地址比较容易,直接通过WifiManager得到。
4.IMEI号,IESI号,手机型号等:
Java代码:
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; // 手机型号
6 String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得
7 }
5.获取手机屏幕高度:
Java代码:
1 private void getWeithAndHeight(){
2 //这种方式在service中无法使用,
3 DisplayMetrics dm = new DisplayMetrics();
4 getWindowManager().getDefaultDisplay().getMetrics(dm);
5 String width = dm.widthPixels; //宽
6 String height = dm.heightPixels; //高
7
8 //在service中也能得到高和宽
9 WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
10 width = mWindowManager.getDefaultDisplay().getWidth();
11 height = mWindowManager.getDefaultDisplay().getHeight();
12 }