Packagecom.itheima.utils;ImportJava.io.BufferedReader;ImportJava.io.File;ImportJava.io.FileInputStream;ImportJava.io.InputStreamReader;ImportAndroid.app.ActivityManager;ImportAndroid.app.ActivityManager.MemoryInfo;ImportAndroid.content.Context;ImportAndroid.text.format.Formatter; Public classRunromutils {//get the Running program Public Static intGetcountrom (Context context) {Activitymanager am=(Activitymanager) context.getsystemservice (context. Activity_service); return am.getrunningappprocesses (). Size (); } //get the remaining running memory space Public StaticString Getavail (context context) {Activitymanager am=(Activitymanager) context.getsystemservice (context. Activity_service); Memoryinfo Outinfo=NewMemoryinfo (); Am.getmemoryinfo (Outinfo); returnformatter.formatfilesize (context, OUTINFO.AVAILMEM); } //get total running memory space Public StaticString gettotal (context context) {//4.1.2 and above can be used this way//Activitymanager am = (activitymanager) context.getsystemservice (context. Activity_service);//memoryinfo outinfo = new Memoryinfo ();//Am.getmemoryinfo (outinfo);//return Formatter.formatfilesize (context, outinfo.totalmem);File File =NewFile ("/proc/meminfo"); FileInputStream Filein; Try{Filein=Newfileinputstream (file); InputStreamReader in=NewInputStreamReader (Filein); BufferedReader BR=NewBufferedReader (in); String result=Br.readline (); String Total= ""; StringBuffer SB=NewStringBuffer (); for(CharC:result.tochararray ()) { if(c>= ' 0 ' &&c<= ' 9 ') {sb.append (c); } } intc = integer.valueof (Sb.tostring ()) *1024; returnformatter.formatfilesize (CONTEXT,C); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); return""; } }}
Android Project gets the number of processes, running memory and remaining running memory