现在的位置: 首页 > 综合 > 正文

Android各种信息的显示 Android各种信息的显示

2017年12月12日 ⁄ 综合 ⁄ 共 15288字 ⁄ 字号 评论关闭

Android各种信息的显示

 929人阅读 评论(0) 收藏 举报

参考自eoeApps。

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

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

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

[java] view
plain
copy

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

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

抱歉!评论已关闭.