I was working on TrafficStats Api and used the following code to get information about All Android Applications
for (ApplicationInfo info : packageManager.getInstalledApplications(0)) {
int uid = info.uid;
CharSequence AppName = packageManager.getApplicationLabel(info);
String packageManager = packageManager.packageManager.getNameForUid(uid).split(":")[0]; }
But when i logged the three variables. It gives confusing result. None of them are unique. For same Uid, many applications are there and in same package name, many Applications are there.See the below log output
AppName is:Phone UID:1001 package: android.uid.phone
AppName is:DM Command Service UID:1001 package: android.uid.phone
AppName is:Dialer Storage UID:1001 package: android.uid.phone
AppName is:SIM Toolkit UID:1001 package: android.uid.phone
Then, how to identify the Applications.
Android uses the package name to uniquely identify apps. You’re printing out the userId name instead of the package name. If you print out the package name you should see a difference. Try this:
String packageName = info.packageName;As for what you’re seeing, Android apps can be configured to share the same signature and userId. All of these settings are set in the AndroidManifest.xml.
For example, the Phone app has this setting
And the Telephony provider has this setting
Notice that they share the same sharedUserId.