Obtain the Linux UID of an Android App

▼魔方 西西 提交于 2019-12-02 17:10:14

Use PackageManager and getApplicationInfo().

adb shell dumpsys package com.example.myapp | grep userId=

pavan
  • The ‍packages.xml file present in /data/system
  • The packages.list file present in /data/system

Contain the list of applications installed and their corresponding UID's.

Ege Kuzubasioglu
PackageManager packageManager = getPackageManager();
try {
    applicationId = String.valueOf(packageManager.getApplicationInfo("com.example.app", PackageManager.GET_META_DATA));
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!