Android各种信息的显示

参考自eoeApps。

在使用eoeApps时,发现它显示的一些系统属性像和用命令行中敲出来的一样,好奇心大起。反编译之,遂得。

关键点为使用ProcessBuilder来执行命令。

另,系统属性的详细信息见:http://blog.csdn.net/jerryutscn/archive/2010/04/24/5519423.aspx

view plaincopy to clipboardprint? 01.package lab.sodino.textimage; 02.import java.io.ByteArrayOutputStream; 03.import java.io.IOException; 04.import java.io.InputStream; 05.import android.app.Activity; 06.import android.app.ActivityManager; 07.import android.content.Context; 08.import android.os.Bundle; 09.import android.telephony.TelephonyManager; 10.import android.util.DisplayMetrics; 11.import android.widget.TextView; 12.public class TextImgAct extends Activity { 13. /** Called when the activity is first created. */ 14. @Override 15. public void onCreate(Bundle savedInstanceState) { 16. super.onCreate(savedInstanceState); 17. setContentView(R.layout.main); 18. TextView txt = (TextView) findViewById(R.id.txt); 19. txt.setBackgroundColor(0xffffffff); 20. txt.setTextColor(0xff0000ff); 21. // txt.setText(getSystemProperty());//显示系统属性 22. // txt.setText(getMemoryInfo(this));//显示内存信息 23. // txt.setText(getVersionInfo());//显示系统版本信息 24. // txt.setText(getCPUInfo());//显示CPU信息 25. // txt.setText(getDiskInfo());//显示盘符信息 26. // txt.setText(getDmesgInfo());//显示dmesg信息 27. // txt.setText(getNetConfigInfo());//显示网络设置信息 28. // txt.setText(getNetStatusInfo());//显示网络状态信息 29. // txt.setText(getMountInfo());//显示Mount信息 30. txt.setText(getTelStatus(this));//显示电话网络信息 31. } 32. /** 33. * System Property文件为:<br/> 34. * 1./default.prop <br/> 35. * 2./system/build.prop <br/> 36. * 3./system/default.prop <br/> 37. * 4./data/local.prop <br/> 38. * 属性信息按照上面的顺序被加载。后加载的属性会覆盖前面的属性值(注:当属性名称相同的时候)。当上面加载完成后,最后加载的是驻留属性,保存在/data 39. * /property文件中。<br/> 40. * 详见:http://blog.csdn.net/jerryutscn/archive/2010/04/24/5519423.aspx 41. */ 42. public static String getSystemProperty() { 43. StringBuffer strBuf = new StringBuffer(); 44. strBuf.append("java.vendor.url=" 45. + System.getProperty("java.vendor.url") + "/n"); 46. strBuf.append("java.class.path=" 47. + System.getProperty("java.class.path") + "/n"); 48. strBuf.append("user.home=" + System.getProperty("user.home") + "/n"); 49. strBuf.append("java.class.version=" 50. + System.getProperty("java.class.version") + "/n"); 51. strBuf.append("os.version=" + System.getProperty("os.version") + "/n"); 52. strBuf 53. .append("java.vendor=" + System.getProperty("java.vendor") 54. + "/n"); 55. strBuf.append("user.dir=" + System.getProperty("user.dir") + "/n"); 56. strBuf.append("user.timezone=" + System.getProperty("user.timezone") 57. + "/n"); 58. strBuf.append("path.separator=" + System.getProperty("path.separator") 59. + "/n"); 60. strBuf.append("os.name=" + System.getProperty("os.name") + "/n"); 61. strBuf.append("os.arch=" + System.getProperty("os.arch") + "/n"); 62. strBuf.append("line.separator=" + System.getProperty("line.separator") 63. + "/n"); 64. strBuf.append("file.separator=" + System.getProperty("file.separator") 65. + "/n"); 66. strBuf.append("user.name=" + System.getProperty("user.name") + "/n"); 67. strBuf.append("java.version=" + System.getProperty("java.version") 68. + "/n"); 69. strBuf.append("java.home=" + System.getProperty("java.home") + "/n"); 70. return strBuf.toString(); 71. } 72. //直接复制的反编译结果,未整理。 73. public static String getDisplayMetrics(Context context) { 74. DisplayMetrics displaymetrics1 = context.getApplicationContext() 75. .getResources().getDisplayMetrics(); 76. int i = displaymetrics1.widthPixels; 77. int j = displaymetrics1.heightPixels; 78. float f = displaymetrics1.density; 79. float f1 = displaymetrics1.xdpi; 80. float f2 = displaymetrics1.ydpi; 81. String s = String.valueOf(""); 82. StringBuilder stringbuilder = (new StringBuilder(s)) 83. .append("The absolute width:"); 84. String s1 = String.valueOf(i); 85. String s2 = String.valueOf(stringbuilder.append(s1).append("pixels/n") 86. .toString()); 87. StringBuilder stringbuilder1 = (new StringBuilder(s2)) 88. .append("The absolute heightin:"); 89. String s3 = String.valueOf(j); 90. String s4 = String.valueOf(stringbuilder1.append(s3).append("pixels/n") 91. .toString()); 92. StringBuilder stringbuilder2 = (new StringBuilder(s4)) 93. .append("The logical density of the display.:"); 94. String s5 = String.valueOf(f); 95. String s6 = String.valueOf(stringbuilder2.append(s5).append("/n") 96. .toString()); 97. StringBuilder stringbuilder3 = (new StringBuilder(s6)) 98. .append("X dimension :"); 99. String s7 = String.valueOf(f1); 100. String s8 = String.valueOf(stringbuilder3.append(s7).append( 101. "pixels per inch/n").toString()); 102. StringBuilder stringbuilder4 = (new StringBuilder(s8)) 103. .append("Y dimension :"); 104. String s9 = String.valueOf(f2); 105. return stringbuilder4.append(s9).append("pixels per inch/n").toString(); 106. } 107. public static String getVersionInfo() { 108. String[] args = { "/system/bin/cat", "/proc/version" }; 109. return exec(args); 110. } 111. public static String getCPUInfo() { 112. String[] args = { "/system/bin/cat", "/proc/cpuinfo" }; 113. return exec(args); 114. } 115. public static String getDiskInfo() { 116. String[] args = { "/system/bin/df" }; 117. return exec(args); 118. } 119. public static String getDmesgInfo() { 120. String[] args = { "/system/bin/dmesg" }; 121. return exec(args); 122. } 123. public static String getNetConfigInfo() { 124. String[] args = { "/system/bin/netcfg" }; 125. return exec(args); 126. } 127. public static String getNetStatusInfo() { 128. String[] args = { "/system/bin/netstat" }; 129. return exec(args); 130. } 131. public static String getMountInfo() { 132. String[] args = { "/system/bin/mount" }; 133. return exec(args); 134. } 135. public static String getMemoryInfo(Context context) { 136. StringBuffer strBuf = new StringBuffer(); 137. ActivityManager actMgr = (ActivityManager) context 138. .getSystemService(Context.ACTIVITY_SERVICE); 139. android.app.ActivityManager.MemoryInfo memoryinfo = new android.app.ActivityManager.MemoryInfo(); 140. actMgr.getMemoryInfo(memoryinfo); 141. strBuf.append("/nTotal Available Memory :"); 142. long l = memoryinfo.availMem >> 10; 143. strBuf.append(l).append("k"); 144. strBuf.append("/nTotal Available Memory :"); 145. long l1 = memoryinfo.availMem >> 20; 146. strBuf.append(l1).append("M"); 147. strBuf.append("/nIn low memory situation:"); 148. boolean flag = memoryinfo.lowMemory; 149. strBuf.append(flag); 150. String[] args = { "/system/bin/cat", "/proc/meminfo" }; 151. strBuf.append(exec(args)); 152. return strBuf.toString(); 153. } 154. public static String exec(String[] args) { 155. String result = ""; 156. ProcessBuilder processBuilder = new ProcessBuilder(args); 157. Process process = null; 158. InputStream is = null; 159. try { 160. process = processBuilder.start(); 161. is = process.getInputStream(); 162. ByteArrayOutputStream baos = new ByteArrayOutputStream(); 163. int read = -1; 164. while ((read = is.read()) != -1) { 165. baos.write(read); 166. } 167. byte[] data = baos.toByteArray(); 168. result = new String(data); 169. } catch (IOException e) { 170. e.printStackTrace(); 171. } finally { 172. if (is != null) { 173. try { 174. is.close(); 175. } catch (IOException e) { 176. e.printStackTrace(); 177. } 178. } 179. if (process != null) { 180. process.destroy(); 181. } 182. } 183. return result; 184. } 185. //直接复制的反编译结果,未整理。 186. public static String getTelStatus(Context context) { 187. TelephonyManager telephonymanager = (TelephonyManager) context 188. .getSystemService("phone"); 189. String s = String.valueOf(""); 190. StringBuilder stringbuilder = (new StringBuilder(s)) 191. .append("DeviceId(IMEI) = "); 192. String s1 = telephonymanager.getDeviceId(); 193. String s2 = String.valueOf(stringbuilder.append(s1).append("/n") 194. .toString()); 195. StringBuilder stringbuilder1 = (new StringBuilder(s2)) 196. .append("DeviceSoftwareVersion = "); 197. String s3 = telephonymanager.getDeviceSoftwareVersion(); 198. String s4 = String.valueOf(stringbuilder1.append(s3).append("/n") 199. .toString()); 200. StringBuilder stringbuilder2 = (new StringBuilder(s4)) 201. .append("Line1Number = "); 202. String s5 = telephonymanager.getLine1Number(); 203. String s6 = String.valueOf(stringbuilder2.append(s5).append("/n") 204. .toString()); 205. StringBuilder stringbuilder3 = (new StringBuilder(s6)) 206. .append("NetworkCountryIso = "); 207. String s7 = telephonymanager.getNetworkCountryIso(); 208. String s8 = String.valueOf(stringbuilder3.append(s7).append("/n") 209. .toString()); 210. StringBuilder stringbuilder4 = (new StringBuilder(s8)) 211. .append("NetworkOperator = "); 212. String s9 = telephonymanager.getNetworkOperator(); 213. String s10 = String.valueOf(stringbuilder4.append(s9).append("/n") 214. .toString()); 215. StringBuilder stringbuilder5 = (new StringBuilder(s10)) 216. .append("NetworkOperatorName = "); 217. String s11 = telephonymanager.getNetworkOperatorName(); 218. String s12 = String.valueOf(stringbuilder5.append(s11).append("/n") 219. .toString()); 220. StringBuilder stringbuilder6 = (new StringBuilder(s12)) 221. .append("NetworkType = "); 222. int i = telephonymanager.getNetworkType(); 223. String s13 = String.valueOf(stringbuilder6.append(i).append("/n") 224. .toString()); 225. StringBuilder stringbuilder7 = (new StringBuilder(s13)) 226. .append("PhoneType = "); 227. int j = telephonymanager.getPhoneType(); 228. String s14 = String.valueOf(stringbuilder7.append(j).append("/n") 229. .toString()); 230. StringBuilder stringbuilder8 = (new StringBuilder(s14)) 231. .append("SimCountryIso = "); 232. String s15 = telephonymanager.getSimCountryIso(); 233. String s16 = String.valueOf(stringbuilder8.append(s15).append("/n") 234. .toString()); 235. StringBuilder stringbuilder9 = (new StringBuilder(s16)) 236. .append("SimOperator = "); 237. String s17 = telephonymanager.getSimOperator(); 238. String s18 = String.valueOf(stringbuilder9.append(s17).append("/n") 239. .toString()); 240. StringBuilder stringbuilder10 = (new StringBuilder(s18)) 241. .append("SimOperatorName = "); 242. String s19 = telephonymanager.getSimOperatorName(); 243. String s20 = String.valueOf(stringbuilder10.append(s19).append("/n") 244. .toString()); 245. StringBuilder stringbuilder11 = (new StringBuilder(s20)) 246. .append("SimSerialNumber = "); 247. String s21 = telephonymanager.getSimSerialNumber(); 248. String s22 = String.valueOf(stringbuilder11.append(s21).append("/n") 249. .toString()); 250. StringBuilder stringbuilder12 = (new StringBuilder(s22)) 251. .append("SimState = "); 252. int k = telephonymanager.getSimState(); 253. String s23 = String.valueOf(stringbuilder12.append(k).append("/n") 254. .toString()); 255. StringBuilder stringbuilder13 = (new StringBuilder(s23)) 256. .append("SubscriberId(IMSI) = "); 257. String s24 = telephonymanager.getSubscriberId(); 258. String s25 = String.valueOf(stringbuilder13.append(s24).append("/n") 259. .toString()); 260. StringBuilder stringbuilder14 = (new StringBuilder(s25)) 261. .append("VoiceMailNumber = "); 262. String s26 = telephonymanager.getVoiceMailNumber(); 263. String s27 = stringbuilder14.append(s26).append("/n").toString(); 264. int l = context.getResources().getConfiguration().mcc; 265. int i1 = context.getResources().getConfiguration().mnc; 266. String s28 = String.valueOf(s27); 267. StringBuilder stringbuilder15 = (new StringBuilder(s28)) 268. .append("IMSI MCC (Mobile Country Code):"); 269. String s29 = String.valueOf(l); 270. String s30 = String.valueOf(stringbuilder15.append(s29).append("/n") 271. .toString()); 272. StringBuilder stringbuilder16 = (new StringBuilder(s30)) 273. .append("IMSI MNC (Mobile Network Code):"); 274. String s31 = String.valueOf(i1); 275. return stringbuilder16.append(s31).append("/n").toString(); 276. } 277.}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sodino/archive/2010/10/14/5941308.aspx

你可能感兴趣的:(Android各种信息的显示)