codelyzer
codelyzer

Reputation: 477

How can I get uid of some other app whose package name I know in android?

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

Upvotes: 7

Views: 11198

Answers (2)

jcomeau_ictx
jcomeau_ictx

Reputation: 38492

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.

Upvotes: 2

codelyzer
codelyzer

Reputation: 477

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();
    }

Upvotes: 11

Related Questions