成都网站建设设计

将想法与焦点和您一起共享

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;
        }

站在用户的角度思考问题,与客户深入沟通,找到大通网站设计与大通网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、网站设计、企业官网、英文网站、手机端网站、网站推广、国际域名空间、虚拟主机、企业邮箱。业务覆盖大通地区。


新闻名称:android系统信息总结
文章位置:http://chengdu.cdxwcx.cn/article/gphjhe.html