Reputation: 2758
I would like to be able to get the Linux UID (user ID) of an installed Android application.
Excerpt from Security and Permissions: "At install time, Android gives each package a distinct Linux user ID. The identity remains constant for the duration of the package's life on that device."
Is there a way to retrieve this UID?
Upvotes: 37
Views: 41686
Reputation: 6672
An easy way on the commandline / in shell scripts is
stat -c '%U' /data/user/0/id.of.app
Upvotes: 0
Reputation: 178
Use android.os.Process.myUid()
to get the calling apps UID directly.
Using the PackageManager is not necessary to find the own UID.
Upvotes: 11
Reputation: 3739
As CommonsWare already wrote, you can use PackageManager
to get the UID.
Here's an example:
int uid;
try {
ApplicationInfo info = context.getPackageManager().getApplicationInfo(
context.getPackageName(), 0);
uid = info.uid;
} catch (PackageManager.NameNotFoundException e) {
uid = -1;
}
Log.i(LOG_TAG, "UID = " + uid);
Upvotes: 3
Reputation: 6282
PackageManager packageManager = getPackageManager();
try {
applicationId = String.valueOf(packageManager.getApplicationInfo("com.example.app", PackageManager.GET_META_DATA));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Upvotes: 4
Reputation: 131
packages.xml
file present in /data/system
packages.list
file present in /data/system
Contain the list of applications installed and their corresponding UID's.
Upvotes: 13