In previous versions of Android, I was able to get CPU usage using top call
String[] cmd = { "sh", "-c", "top -m 1000 -d 0 -n 1 | grep \"" + aAppPID + "\""}; lProcess = Runtime.getRuntime().exec(cmd); BufferedReader lReader = new BufferedReader(new InputStreamReader(lProcess.getInputStream()));
Android 7 seems to have changed security or something to prevent this. Now, if it is connected to Android Studio, it will give me a line with the processor% of 1. If you run the release version, I see that it does not return any lines.
Does anyone know if there is a permission that can be added to allow this?
My best guess is that the permission entries mentioned here have something to do with this issue.
https://developer.android.com/about/versions/nougat/android-7.0-changes.html#perm
Here is a link to another question on which I posted a solution for loading the processor on Pre-7 releases.
How to get the overall CPU usage of an application from / proc / pid / stat?
android android-7.0-nougat android-permissions
GR Envoy
source share