/**   *  获取系统中所有安装包信息   */public String getAllPackages(Context context){String appList = "";List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(0);for (PackageInfo packageInfo : packages) {// 这里可以控制是否需要获取系统级别的packageif ((packageInfo.applicationInfo.flags &  ApplicationInfo.FLAG_SYSTEM) == 0){appList += packageInfo.applicationInfo.loadLabel(getPackageManager()).toString() + ",";}}return appList.substring(0, appList.length()-1);}/**   *  获取系统内存信息   */public String getSysMemoryInfo(Context context){long freeMem = 0;long totalMem = 0;ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);MemoryInfo memoryInfo = new MemoryInfo();activityManager.getMemoryInfo(memoryInfo);freeMem = memoryInfo.availMem/1024/1024;//读取指定文件信息 String path = "/proc/meminfo";        String content = null;        BufferedReader br = null;        try {            br = new BufferedReader(new FileReader(path), 8);            String line;            if ((line = br.readLine()) != null) {                content = line;            }        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        } finally {            if (br != null) {                try {                    br.close();                } catch (IOException e) {                    e.printStackTrace();                }            }        }        // beginIndex        int begin = content.indexOf(':');        // endIndex        int end = content.indexOf('k');        // 截取字符串信息content = content.substring(begin + 1, end).trim();    totalMem = Integer.parseInt(content)/1024;    return freeMem+" "+totalMem;}/** * 获取CPU信息 */    private String getCpuInfo() {               String str1 = "/proc/cpuinfo";              String str2 = "";                String cpuInfo="";  //1-cpu型号  //2-cpu频率                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 =  arrayOfString[i] + "  ";                   }                   str2 = localBufferedReader.readLine();                  arrayOfString = str2.split("\\s+");                  cpuInfo =cpuInfo + arrayOfString[2];                   localBufferedReader.close();               } catch (IOException e) {               }               return cpuInfo;           }      /** * 获取MAC地址  */       private String getMacAddress(){                  String result = "";              WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);                   WifiInfo wifiInfo = wifiManager.getConnectionInfo();               result = wifiInfo.getMacAddress();               // Log.i(TAG, "macAdd:" + result);                return result;          }            /**    * 获取其他手机信息     */       private String getInfo() {                TelephonyManager mTm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);                 String imei = mTm.getDeviceId();                  String imsi = mTm.getSubscriberId();                 String mtype = android.os.Build.MODEL; // 手机型号                   String numer = mTm.getLine1Number(); // 手机号码                                  return imei + " " + imsi + " " + mtype + " " + numer;            }               /**       * 获取屏幕的分辨率       */       private String getWeithAndHeight(){                 //这种方式在service中无法使用,                DisplayMetrics dm = new DisplayMetrics();                getWindowManager().getDefaultDisplay().getMetrics(dm);                int width = dm.widthPixels;              //宽                int height = dm.heightPixels;           //高                          //在service中也能得到高和宽               WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);                int width0 = mWindowManager.getDefaultDisplay().getWidth();                int height0 = mWindowManager.getDefaultDisplay().getHeight();                              return ""+width +" "+height + " " +width0 + " " +height0;            }  



作者:newjerryj 发表于2013-4-25 23:58:40 原文链接 阅读:145 评论:0 查看评论

更多相关文章

  1. Android获取地理位置信息(GPS/NETWORK)
  2. Android社交系统----界面预览
  3. android(8)(获取手机系统内存和SD卡内存信息)
  4. js判断移动终端浏览器版本信息
  5. 移动端区分安卓系统和ios系统
  6. android自己开发的系统软件报错
  7. 转来的··调用系统相机拍照和调用相册
  8. Android studio 编译异常信息记录
  9. android的input_event的流程,以及如何获取输入设备的相关信息

随机推荐

  1. android 打造可复用的底部dialog
  2. Android(安卓)协调者布局 CoordinatorLay
  3. android预览word(WPS预览)
  4. Android中多USB摄像头解决方案——UVCCam
  5. [Android] Intent 传递对象
  6. [Android]DrawerLayout中Toolbar遮挡问题
  7. [译] 了解 Android(安卓)的矢量图片格式:V
  8. 如何绑定按键与程序
  9. E/ServiceManager( 54): add_service('le
  10. android使用百度地图SDK获取定位信息示例