温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android系统信息总结

发布时间:2020-03-25 17:15:28 来源:网络 阅读:367 作者:huangmeicai 栏目:移动开发

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI