6

I want to get uid of whatsapp in android, and I know Whatsapp's package name. How can I do this? Thank you.

codelyzer
  • 467
  • 1
  • 4
  • 17

2 Answers2

11

I found WhatsApp's uid with the following code

int uid = 0;
    try {
        uid = this.getPackageManager().getApplicationInfo("com.whatsapp", 0).uid;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
codelyzer
  • 467
  • 1
  • 4
  • 17
1
PACKAGENAME=termux
jcomeau@aspire:~$ adb shell ps -n | grep $PACKAGENAME
10114     17830 246   769444 40176 SyS_epoll_ 00000000 S com.termux
10114     17856 17830 12164  2032  poll_sched 00000000 S /data/data/com.termux/files/usr/bin/bash

this worked on a BLU Dash X2 with Android version 6.0.

also, the username matches the UID, i.e. 10114 has a username of u0_a114.

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • Since Android O, you have to [use `ps -A` instead of `ps -n`](https://stackoverflow.com/questions/44732749/how-to-make-adb-shell-ps-list-all-processes-in-android-o). – Martin Braun Sep 23 '22 at 20:28