我在获取 UID 时做错了什么
我在这里看到了类似类型的帖子。但是我没有得到这个权利。为了获取我写的正在运行的进程的UID,
ActivityManager mgr = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = mgr.getRunningAppProcesses();
String text = "All Process:\n";
for (int i = 1; i <= processes.size(); i++)
{
String s;
s = processes.get(i - 1).processName.toString();
text += "Process:" + i + s + ":UID:" + android.os.Process.getUidForName(s) + "\n";
}
但是在循环完成后,我在字符串文本中得到的所有UID值都是-1。我将GET_TASKS权限设置为在清单文件中。为什么我没有获得 UID。请帮忙。我需要这个 UID 来终止进程。
I saw similar types of posts here.But i am not getting this right.To get the UID of running process i wrote
ActivityManager mgr = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = mgr.getRunningAppProcesses();
String text = "All Process:\n";
for (int i = 1; i <= processes.size(); i++)
{
String s;
s = processes.get(i - 1).processName.toString();
text += "Process:" + i + s + ":UID:" + android.os.Process.getUidForName(s) + "\n";
}
But after completion of loop what i am getting in the string text is all UID value as -1.I put GET_TASKS permission in manifest file.Why i am not getting the UID.Please help.I need this UID to kill the process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了杀死进程,我使用了 ActivityManager 的killBackgroundProcess方法。它需要包名称而不是UID
To kill the process i used killBackgroundProcess Method of ActivityManager.It needs package name not the UID
请参阅@seanhodges 的回答以供参考。
阅读整个线程也可能会有所帮助。
Please see this answer by @seanhodges for reference.
Reading the whole thread might be helpful too.