【问题标题】:How can I use hardwarepropertiesmanager(android) in android api 30, android 11如何在 android api 30、android 11 中使用 hardwarepropertymanager(android)
【发布时间】:2022-12-19 14:17:33
【问题描述】:

现在我想跑

HardwarePropertiesManager hardwarePropertiesManager = getApplicationContext().getSystemService(HardwarePropertiesManager.class);
        hardwarePropertiesManager.getDeviceTemperatures(HardwarePropertiesManager.DEVICE_TEMPERATURE_CPU, HardwarePropertiesManager.TEMPERATURE_CURRENT);

检查CPU使用率和温度..

但是,发生了异常,即

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.example.___/com.example.___.MainActivity}: 
java.lang.SecurityException: The caller is neither a device 
owner, nor holding the DEVICE_POWER permission, nor the current 
VrListener.

有什么方法可以检查 cpu 温度和 cpu 使用情况(内存,内核)??

【问题讨论】:

    标签: java android android-11 android-api-30


    【解决方案1】:

    正如文档中提到的 HardwarePropertiesManager 可用于设备所有者的应用程序 - https://developer.android.com/reference/android/os/HardwarePropertiesManager

    您可以尝试从文件中读取数据

    系统/类/hwmon/hwmonX/temp1_input

    有一些变化基于供应商。完整列表可以参考https://stackoverflow.com/a/59306562

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-12
      相关资源
      最近更新 更多