• android项目得到进程数量,运行内存和剩余运行内存


    package com.itheima.utils;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    
    import android.app.ActivityManager;
    import android.app.ActivityManager.MemoryInfo;
    import android.content.Context;
    import android.text.format.Formatter;
    
    public class RunRomUtils {
        //得到运行的程序
        public static int getCountRom(Context context){
            ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
            return am.getRunningAppProcesses().size();
            
        }
        //得到剩余运行内存空间
        public static String getAvail(Context context){
            ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
            MemoryInfo outInfo = new MemoryInfo();
            am.getMemoryInfo(outInfo );
            
            return Formatter.formatFileSize(context, outInfo.availMem);
        }
        //得到总运行内存空间
        public static String getTotal(Context context){
            //4.1.2及以上可以用这个办法
    //        ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    //        MemoryInfo outInfo = new MemoryInfo();
    //        am.getMemoryInfo(outInfo );
    //        return Formatter.formatFileSize(context, outInfo.totalMem);
            File file = new File("/proc/meminfo");
            FileInputStream fileIn;
            try {
                fileIn = new FileInputStream(file);
                InputStreamReader in = new InputStreamReader(fileIn);
                BufferedReader br = new BufferedReader(in);
                String result = br.readLine();
                String total = "";
                StringBuffer sb = new StringBuffer();
                for (char c : result.toCharArray()) {
                    if(c>='0'&&c<='9'){
                        sb.append(c);
                    }
                }
                int c = Integer.valueOf(sb.toString())*1024;
                return Formatter.formatFileSize(context,c);
                
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return "";
            }
        }
    }
  • 相关阅读:
    element表格添加序号
    ZOJ 3822 Domination(概率dp)
    HDU 3037(Lucas定理)
    HDU 5033 Building(单调栈维护凸包)
    HDU 5037 Frog(贪心)
    HDU 5040 Instrusive(BFS+优先队列)
    HDU 5120 Intersection(几何模板题)
    HDU 5115 Dire Wolf(区间dp)
    HDU 5119 Happy Matt Friends(dp+位运算)
    C++ string详解
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/5040172.html
Copyright © 2020-2023  润新知