AbhishekB
AbhishekB

Reputation: 2075

Detect applications with same sharedUserId

Is there a way to get applications having same shareUserId from a third application. I mean i wish to detect the 2 applications having same sharedUserId from my application.

Upvotes: 0

Views: 910

Answers (2)

Philip Brito
Philip Brito

Reputation: 5599

I'm going to just improve the answer from @Marcin Orlowski here.

The way to get the sharedUserId in Kotlin is:

context.packageManager.getPackageInfo(context.packageName, 0).sharedUserId

But it only works if you have defined the sharedUserId on the app's Manifest file, otherwise you'll get a null return when calling the above code.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:sharedUserId="your-sharedUserId"

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

Use PackageManager and check user Id of each of installed package. There is sharedUserId field in PackageInfo structure which will be set if package uses it.

Upvotes: 4

Related Questions