Obtain the Linux UID of an Android App

前端 未结 6 2153
半阙折子戏
半阙折子戏 2020-12-23 12:23

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 e

相关标签:
6条回答
  • 2020-12-23 12:31

    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);
    
    0 讨论(0)
  • 2020-12-23 12:34

    Use android.os.Process.myUid() to get the calling apps UID directly.

    Using the PackageManager is not necessary to find the own UID.

    0 讨论(0)
  • 2020-12-23 12:41

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

    0 讨论(0)
  • 2020-12-23 12:43
    • 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.

    0 讨论(0)
  • 2020-12-23 12:48

    Use PackageManager and getApplicationInfo().

    0 讨论(0)
  • 2020-12-23 12:49
    PackageManager packageManager = getPackageManager();
    try {
        applicationId = String.valueOf(packageManager.getApplicationInfo("com.example.app", PackageManager.GET_META_DATA));
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    
    0 讨论(0)
提交回复
热议问题