简体   繁体   English

在Android上检索设备信息

[英]Retrieving Device Information on Android

My program is targeting Android 1.5. 我的计划是针对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. 通过搜索API,我发现很少有用的类。 the best I've found so far is the Runtime class and a few Build.* system properties. 到目前为止我发现的最好的是Runtime类和一些Build.*系统属性。

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. 我希望能够获得有关设备上的总内存量,可用内存量的信息(我不知道Runtime类是否真的给了我,因为它特别指的是JVM可用的内存)以及有关处理器的信息。

Is this information available, and if so, where can I find it? 这些信息是否可用,如果可以,我在哪里可以找到它?

"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). “内存总量”毫无意义(例如G1有192MB的物理RAM,其中90-100MB可用于不同版本的内核和应用程序,但不包括用于窗口缓冲区和各种内存的内存其他东西,每个Java应用程序的堆的限制为16MB,因此系统的可用RAM更多地是关于可以同时运行多少进程的数据。

"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. 我们通常会尝试让尽可能多的应用程序继续运行,因为有可用内存,因此在普通Linux缓存和普通Linux缓存之间通常几乎没有空闲内存。 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. 我现在提出的最好的方法是查看系统的内存状态,这是2.0中引入的“运行服务”UI。 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. 您可以通过android.os.Build.CPU_ABI找到NDK代码的CPU架构。 This gives you a baseline for the CPU architecture, but information like whether the CPU supports NEON instructions or such. 这为您提供了CPU架构的基线,但是有关CPU是否支持NEON指令等信息。 For that kind of information, you could conceivably use the NDK to run some native code to interrogate the CPU. 对于这种信息,您可以设想使用NDK运行一些本机代码来查询CPU。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM