android系统信息总结-创新互联

1. 总内存(ram)
  android 内存信息在 /proc/meminfo中,可以通过读取此文件获取信息。
  public void getTotalMemory() {
               String str1 = "/proc/meminfo";
               String str2="";
               try {
                       FileReader fr = new FileReader(str1);
                       BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
                       while ((str2 = localBufferedReader.readLine()) != null) {
                               Log.i(TAG, "---" + str2);
                       }
               } catch (IOException e) {
               }
       }
 2. 获取当前可用内存
   public long getAvailMemory() {
               ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
               ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
               am.getMemoryInfo(mi);
               return mi.availMem;
       }

 3. 获取rom大小
   public long[] getRomMemroy() {
               long[] romInfo = new long[2];
               File root = Environment.getRootDirectory();
               StatFs sf = new StatFs(root.getPath());
               long bSize = sf.getBlockSize();
               long bCount = sf.getBlockCount();
               long availBlocks = sf.getAvailableBlocks();
               romInfo[0] = bSize * bCount;// Total size
               romInfo[1] = bSize * availBlocks;// Available size
               return romInfo;
       }

 4. 获取SD卡容量
   public long[] getSDCardMemory() {
               long[] sdCardInfo=new long[2];
               String state = Environment.getExternalStorageState();
               if (Environment.MEDIA_MOUNTED.equals(state)) {
                       File sdcardDir = Environment.getExternalStorageDirectory();
                       StatFs sf = new StatFs(sdcardDir.getPath());
                       long bSize = sf.getBlockSize();
                       long bCount = sf.getBlockCount();
                       long availBlocks = sf.getAvailableBlocks();

                       sdCardInfo[0] = bSize * bCount;// Total size
                       sdCardInfo[1] = bSize * availBlocks;// Available size
               }
               return sdCardInfo;
       }

   5. 获取电量
      private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){
               @Override
               public void onReceive(Context context, Intent intent) {
                       int level = intent.getIntExtra("level", 0);
                       //     level Plus % Is the current power of the
       }
       };
   在 activity中注册
   registerReceiver(batteryReceiver,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
 6. CPU信息
     public String[] getCpuInfo() {
               String str1 = "/proc/cpuinfo";
               String str2="";
               String[] cpuInfo={"",""};
               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[0] = cpuInfo[0] + arrayOfString[i] + " ";
                       }
                       str2 = localBufferedReader.readLine();
                       arrayOfString = str2.split("\\s+");
                       cpuInfo[1] += arrayOfString[2];
                       localBufferedReader.close();
               } catch (IOException e) {
               }
               return cpuInfo;
       }

创新互联建站是一家做网站、成都网站建设,提供网页设计,网站设计,网站制作,建网站,按需策划,网站开发公司,从2013年成立是互联行业建设者,服务者。以提升客户品牌价值为核心业务,全程参与项目的网站策划设计制作,前端开发,后台程序制作以及后期项目运营并提出专业建议和思路。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:android系统信息总结-创新互联
网页路径:http://bzwzjz.com/article/icgps.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 品牌网站建设 重庆网站建设 专业网站建设 定制网站制作 成都h5网站建设 高端网站设计 成都网站建设 宜宾网站设计 手机网站建设 成都企业网站设计 营销型网站建设 网站建设公司 成都网站制作 成都网站设计公司 定制网站建设 成都网站设计制作公司 成都网站设计 成都网站制作 成都网站制作 成都网站制作 成都做网站建设公司 手机网站制作设计