1

Now I'm trying to run

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

to check cpu usage and temperature..

but, the exception occurred, which is

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.

is there any method to check cpu temperature and cpu usage(memory, core)??

Malik Saifullah
  • 522
  • 1
  • 6
  • 22
BePositve
  • 11
  • 2

1 Answers1

1

As the documentation mentions HardwarePropertiesManager is available for applications which are device owners - https://developer.android.com/reference/android/os/HardwarePropertiesManager

You can try reading the data from file

sys/class/hwmon/hwmonX/temp1_input

There are some changes based on vendors. You can refer to https://stackoverflow.com/a/59306562 for comprehensive list.

yeshu
  • 192
  • 1
  • 10