Android: How do you get internal Total/Available memory?

元气小坏坏 提交于 2019-12-19 04:23:09

问题


There's a difference between RAM memory and internal flash memory right? I can get RAM memory by:

cat /proc/meminfo

However, I am not sure how to get Flash memory information.

I think I know how to get available memory:

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

Does this give available internal Flash memory?

How about total internal memory?

Does following unix command get me this info?

df

result:

Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    97744         0     97744   0% /dev
tmpfs                     4096         0      4096   0% /sqlite_stmt_journals
/dev/block/mtdblock3    174080    154372     19708  89% /system
/dev/block/mtdblock5    169728     57144    112584  34% /data
/dev/block/mtdblock4    133120     89632     43488  67% /cache
/dev/block/mtdblock4    133120     89632     43488  67% /data/dalvik-cache
/dev/block//vold/179:1
                       7970928   2358576   5612352  30% /sdcard

if so, do I have to add all tmpfs & /dev/block/mtdblock# to get total internal memory?


回答1:


df tells you about the space on file systems... ie, think of flash as 'disk'

As for adding it up... depends on what you want to know. Adding up distinct partitions is a bit dubious since they aren't exactly interchangeable. And there are other mtd partitions that don't have file systems or don't get mounted during normal operation - they contain things like bootloaders, radio firmware, the linux kernel and compressed root filesystem, and also the kernel and compressed file system for the recovery system.

You might do better to look through the kernel boot messages and see what it finds in the way of ram and mtd devices.

But then, there's also internal memory that is not accessible to the kernel and is instead used by the radio coprocessor. So if you actually want the total installed, it's probably best to read the manufacturers specifications.

Otherwise, you should stick to the memory that might conceivably be available to applications...




回答2:


cat /proc/meminfo

will give you some information about the running memory, but Dalvik tends to take as much memory as possible...

To dig more into the Android memory, you should use DDMS.



来源:https://stackoverflow.com/questions/4350580/android-how-do-you-get-internal-total-available-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!