Search code examples
androiduid

What i am doing wrong to get the 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.


Solution

  • To kill the process i used killBackgroundProcess Method of ActivityManager.It needs package name not the UID