简体   繁体   English

如何使用 Kotlin Android 以编程方式获取 CPU 使用率?

[英]How to get CPU usage programmatically with Kotlin Android?

I want to get CPU usage programmatically with Kotlin in an Android application.我想在 Android 应用程序中使用 Kotlin 以编程方式获取 CPU 使用率。 I tried using the HardwarePropertiesManager class but it seems like it can only be used in devices that are in enterprise mode, is there any alternative?我尝试使用HardwarePropertiesManager class 但它似乎只能在企业模式下的设备中使用,还有其他选择吗?

If you look at this repo ( https://github.com/AntonioRedondo/AnotherMonitor#retrieving-processes-info-since-android-oreo-80-api-26-august-2017 ), it is not possible since Android 8.0 (API 26).如果您查看此存储库( https://github.com/AntonioRedondo/AnotherMonitor#retrieving-processes-info-since-android-oreo-80-api-26-august-2017 ),这是不可能的,因为 ZE84E30B9390CDB64DB6DB2C9AB87846. API 26)。 Seems like you can get only memory usage.似乎您只能获得 memory 使用情况。 However, if you still want for old versions, you can look at that repo to know how to get CPU usage, and convert Java code to Koltin (which is easy).但是,如果您仍然想要旧版本,您可以查看该存储库以了解如何获取 CPU 使用率,并将 Java 代码转换为 Koltin(这很容易)。

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

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