I have an application that uses the traffic stats API to see which running processes are using the network.
I used to do it by getting the uid obtained through the getRunningAppProcesses()
method. Apparently this has been changed in Android M to only return your application package name as shown here.
My question is: Is there another way to get the Name and UID of every running processes in Android M?
Here is a sample of how I was doing this before, I would like to recreate this functionality on Android M.
List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
PackageManager pm = context.getPackageManager();
for (int i = 0; i < procInfos.size(); i++) {
try {
String packageName = procInfos.get(i).processName;
String appName = "";
try {
appName = pm.getApplicationLabel(
pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA))
.toString();
} catch (NameNotFoundException e) {
appName = "";
}
int uid = procInfos.get(i).uid;
long ulBytes = TrafficStats.getUidTxBytes(uid);
long dlBytes = TrafficStats.getUidRxBytes(uid);
// Do other stuff.
Any help is very appreciated. Thanks!