有没有办法让应用程序 CPU 使用 Android 7(牛轧糖)
Is there a way to get Application CPU usage with Android 7 (nougat)
在 Android 的先前版本中,我能够通过使用 top 调用
获得 CPU 用法
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 更改了安全性或其他内容以不允许这样做。现在,如果附加到 Android Studio,它将给我一行 CPU % 的 1。如果 运行 发布版本,我看到它没有 return 任何线。
有谁知道是否有可以添加的权限来允许这样做?
我最好的猜测是此处记录的权限说明与此问题有关。
https://developer.android.com/about/versions/nougat/android-7.0-changes.html#perm
这里是 link 另一个问题,我发布了一个解决方案以获得 CPU 在 Pre-7 版本上的使用。
How do I get the total CPU usage of an application from /proc/pid/stat?
现在我们已经转向奥利奥,似乎 Google 继续取消此功能作为安全问题,如果他们打开任何新的功能,我会感到震惊 API 来替换它。请参阅以下问题跟踪器,其中包含来自 Google 的某人的一些评论。他们最好的建议是使用
/proc/self/stat 而不是 /proc/stat
在 Android 的先前版本中,我能够通过使用 top 调用
获得 CPU 用法 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 更改了安全性或其他内容以不允许这样做。现在,如果附加到 Android Studio,它将给我一行 CPU % 的 1。如果 运行 发布版本,我看到它没有 return 任何线。
有谁知道是否有可以添加的权限来允许这样做?
我最好的猜测是此处记录的权限说明与此问题有关。
https://developer.android.com/about/versions/nougat/android-7.0-changes.html#perm
这里是 link 另一个问题,我发布了一个解决方案以获得 CPU 在 Pre-7 版本上的使用。
How do I get the total CPU usage of an application from /proc/pid/stat?
现在我们已经转向奥利奥,似乎 Google 继续取消此功能作为安全问题,如果他们打开任何新的功能,我会感到震惊 API 来替换它。请参阅以下问题跟踪器,其中包含来自 Google 的某人的一些评论。他们最好的建议是使用 /proc/self/stat 而不是 /proc/stat