tags:

views:

1118

answers:

2

My program is targeting Android 1.5. I would like to retrieve system information about the device itself. I have found very few helpful classes by searching the APIs. the best I've found so far is the Runtime class and a few Build.* system properties.

I would like to be able to get information like the total amount of memory on the device, the amount of free memory (which I do not know if the Runtime class is acutally giving me, since it specifically refers to memory available to the JVM) along with information about the processor.

Is this information available, and if so, where can I find it?

A: 

For data that is visible in the Settings application, you can look at the source code to that application and see if the way they are getting that information is part of the published SDK.

CommonsWare
I will try to download the android source and see what I can find. I'll report back what I find so others can use this information.
Brandon
In trying to download the source from home, I see that it is telling me that a Windows OS is not supported, which is all I have to work with. I can not use Linux or a Mac at my company.
Brandon
Use Google Code Search, or browse the source code through the Web (links on source.android.com).
CommonsWare
+1  A: 

"Total amount of memory" is pretty meaningless (for example G1 has 192MB of physical RAM, of which between 90-100MB has been available to the kernel and apps across different releases, but that doesn't include memory used for window buffers and various other things, and each Java application has a limit of 16MB for its heap, so the available RAM to the system is more about how many processes can be running at the same time).

"Amount of free memory" is really really meaningless. We generally try to let as many applications remain running as there is available memory, so between that and normal Linux caches there generally is little no free memory. If you do look at the raw free memory in the kernel, you will see that varying pretty crazily over time as applications start up and use some memory, pushing it down, then other applications get expunged causing it to jump way back up until caches and other things have a chance to gobble it back up.

The best way I have come up at this point to look at the memory state of the system is the "Running services" UI that was introduced in 2.0. Yes, the memory information at the bottom is horribly subtle and meaningless to most people; we should try to figure out how to improve it. :)

You can find out the CPU architecture for NDK code via android.os.Build.CPU_ABI. This gives you a baseline for the CPU architecture, but information like whether the CPU supports NEON instructions or such. For that kind of information, you could conceivably use the NDK to run some native code to interrogate the CPU.

hackbod
This application is being designed for Android 1.5 to allow for maximum compatibility across devices, and this is a constraint I cannot control. Using Build.CPU_ABI is not an option (available starting in 1.6), and nor is the UI that was introduced in 2.0. I need the total and free amounts of memory for reporting statistics about the device, even if those values are fairly worthless in any practical situation . I will look into using the NDK, but I was under the impression that it was fairly limited in capability and used mainly for streamlining calculation-intensive operations.
Brandon