机器人 - 如何让我的Andr​​oid设备的内存使用情况 [英] android - How to get Memory usage of my android device

查看:143
本文介绍了机器人 - 如何让我的Andr​​oid设备的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您的朋友是如何做的,希望最好的。 朋友,我想怎么有多少内存我的Andr​​oid设备确实有多少内存使用 活动内存,活动内存,可用内存和MB有线内存 我已经通过<一个了href="http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android">this链接它说关于通过解析/系统/斌/猫,的/ proc / meminfo中,我们可以得到我上面提到的事情,是的,我让所有的事情,但我得到一个长字符串在这里我拥有了一切。

  MemTotal:377192 KB
  MemFree:10448 KB
  缓冲区:1368 kB``
  缓存:74276 KB
  SwapCached:0 KB
  主动:143116 KB
  无效:177292 KB
  活动(匿名):118388 KB
  非活动(匿名):137664 KB
  活动(文件):24728 KB
  非活动(文件):39628 KB
    Unevictable:10664 KB
    Mlocked:10372 KB
    HighTotal:190464 KB
    HighFree:568 KB
    LowTotal:186728 KB
    LowFree:9880 KB
    SwapTotal:0 KB
    SwapFree:0 KB
脏:8 KB
回写:0 KB
AnonPages:255440 KB
映射:45816 KB
SHMEM:624 KB
板坯:10952 KB
SReclaimable:2456 KB
SUnreclaim:8496 KB
 

更大的字符串这个我收到来自

 私人字符串ReadCPUinfo()
{
的ProcessBuilder CMD;
StringBuffer的strMemory =新的StringBuffer();
//最后ActivityManager activityManager =(ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager actvityManager =(ActivityManager)this.getSystemService(
ACTIVITY_SERVICE);
ActivityManager.MemoryInfo明复=新ActivityManager.MemoryInfo();
actvityManager.getMemoryInfo(明复);
strMemory.append(可用内存:);
strMemory.append(mInfo.availMem / 1048576L);
strMemory.append(\ N);
strMemory.append(\ N);
字符串结果= strMemory.toString();
尝试{
字串[] args = {/系统/斌/猫,的/ proc / meminfo中};
CMD =新的ProcessBuilder(参数);
工艺过程= cmd.start();
在的InputStream = process.getInputStream();
byte []的重新=新的字节[1024];
而(in.read(再)!= -1){
的System.out.println(itthhe ==== ---&GT;&GT;&GT;&GT;+新的String(重新));
结果=结果+新的String(重);
}
附寄();
}赶上(IOException异常前){
ex.printStackTrace();
}
返回结果;
}
 

我想我是否可以动态地打破这个字符串差异。设备或是否有任何其他的方法找出上面的东西

我也通过这个但它是也不能使用全..我很容易就能获得可用内存信息,但我需要所有四个

任何帮助深表AP preciated 感谢adavance

解决方案

  ActivityManager activityManager =(ActivityManager)context.getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo =新ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);

Log.i(TAG,memoryInfo.availMem+ memoryInfo.availMem +\ N);
Log.i(TAG,memoryInfo.lowMemory+ memoryInfo.lowMemory +\ N);
Log.i(TAG,memoryInfo.threshold+ memoryInfo.threshold +\ N);

名单&LT; RunningAppProcessInfo&GT; runningAppProcesses = activityManager.getRunningAppProcesses();

地图&LT;整数,字符串&GT; pidMap =新TreeMap的&LT;整数,字符串&GT;();
对于(RunningAppProcessInfo runningAppProcessInfo:runningAppProcesses)
{
    pidMap.put(runningAppProcessInfo.pid,runningAppProcessInfo.processName);
}

收藏&LT;整数GT;键= pidMap.keySet();

对于(INT键:键)
{
    INT的PID [] =新INT [1];
    PID的[0] =键;
    android.os.Debug.MemoryInfo [] memoryInfoArray = activityManager.getProcessMemoryInfo(PID)的;
    对于(android.os.Debug.MemoryInfo pidMemoryInfo:memoryInfoArray)
    {
        Log.i(TAG,的String.Format(** meminfo中的PID%D [%S] ** \ N,PID的[0],pidMap.get(PID的[0])));
        Log.i(TAG,pidMemoryInfo.getTotalPrivateDirty():+ pidMemoryInfo.getTotalPrivateDirty()+\ N);
        Log.i(TAG,pidMemoryInfo.getTotalPss():+ pidMemoryInfo.getTotalPss()+\ N);
        Log.i(TAG,pidMemoryInfo.getTotalSharedDirty():+ pidMemoryInfo.getTotalSharedDirty()+\ N);
    }
}
 

请参阅<一href="http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android">How发现我的Andr​​oid应用程序的内存使用情况

这就是你所需要的;)

how you friends are doing, hope for the best. friends i want to how how much memory my android device does have and how much memory is used active memory , inactive memory, free memory and wired memory in MB i have gone through this link which says about that by parsing "/system/bin/cat", "/proc/meminfo" we can get things which i mentioned above, and yes i am getting all the things but i am getting a long string where i have everything

 MemTotal:         377192 kB
  MemFree:           10448 kB
  Buffers:            1368 kB``
  Cached:            74276 kB
  SwapCached:            0 kB
  Active:           143116 kB
  Inactive:         177292 kB
  Active(anon):     118388 kB
  Inactive(anon):   137664 kB
  Active(file):      24728 kB
  Inactive(file):    39628 kB
    Unevictable:       10664 kB
    Mlocked:           10372 kB
    HighTotal:        190464 kB
    HighFree:            568 kB
    LowTotal:         186728 kB
    LowFree:            9880 kB
    SwapTotal:             0 kB
    SwapFree:              0 kB
Dirty:                 8 kB
Writeback:             0 kB
AnonPages:        255440 kB
Mapped:            45816 kB
Shmem:               624 kB
Slab:              10952 kB
SReclaimable:       2456 kB
SUnreclaim:         8496 kB

even bigger string this i am getting from

 private String ReadCPUinfo()
{
ProcessBuilder cmd;
StringBuffer strMemory = new StringBuffer();
//final ActivityManager activityManager =(ActivityManager) 
context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager actvityManager = (ActivityManager) this.getSystemService(  
ACTIVITY_SERVICE );
ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo ();
actvityManager.getMemoryInfo( mInfo );
strMemory.append("Available Memory : ");
strMemory.append(mInfo.availMem/1048576L);
strMemory.append("\n");
strMemory.append("\n");
String result=strMemory.toString();
try{
String[] args = {"/system/bin/cat", "/proc/meminfo"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println("itthhe   ====  ---   >>>>    "+new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}

i want to whether i can break this string dynamically for diff. devices or is there any other way to find out above things

i have also gone through this but it was also not that use full .. i am easily able to get available memory info but i need all four

any help is deeply appreciated thanks in adavance

解决方案

ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);

Log.i(TAG, " memoryInfo.availMem " + memoryInfo.availMem + "\n" );
Log.i(TAG, " memoryInfo.lowMemory " + memoryInfo.lowMemory + "\n" );
Log.i(TAG, " memoryInfo.threshold " + memoryInfo.threshold + "\n" );

List<RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses();

Map<Integer, String> pidMap = new TreeMap<Integer, String>();
for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses)
{
    pidMap.put(runningAppProcessInfo.pid, runningAppProcessInfo.processName);
}

Collection<Integer> keys = pidMap.keySet();

for(int key : keys)
{
    int pids[] = new int[1];
    pids[0] = key;
    android.os.Debug.MemoryInfo[] memoryInfoArray = activityManager.getProcessMemoryInfo(pids);
    for(android.os.Debug.MemoryInfo pidMemoryInfo: memoryInfoArray)
    {
        Log.i(TAG, String.format("** MEMINFO in pid %d [%s] **\n",pids[0],pidMap.get(pids[0])));
        Log.i(TAG, " pidMemoryInfo.getTotalPrivateDirty(): " + pidMemoryInfo.getTotalPrivateDirty() + "\n");
        Log.i(TAG, " pidMemoryInfo.getTotalPss(): " + pidMemoryInfo.getTotalPss() + "\n");
        Log.i(TAG, " pidMemoryInfo.getTotalSharedDirty(): " + pidMemoryInfo.getTotalSharedDirty() + "\n");
    }
}

See How to discover memory usage of my application in Android

That's all you need ;)

这篇关于机器人 - 如何让我的Andr​​oid设备的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆