Prateek Jain
Prateek Jain

Reputation: 1234

How to get the application id in Android?

I need to uniquely identify Android app installed on any Android device. I know that every Android device has unique id and every application is like a Linux user for Android.

But there are cases when two applications can have same userID if they are signed with the same key and are designed to share content.

Is there any way to identify unique id for every application on every android device ? I want to broadcast something based on this unique id and then the application should receive that and act accordingly.

Can we also get the application id / user id via code ?

Thanks in advance !!

Cheers, Prateek

Upvotes: 2

Views: 5785

Answers (3)

saif
saif

Reputation: 21

Yes, we can get application id of each application installed on device by using the following code. And if you are signing by the same key also, application package name will be different.

ResolveInfo info = mApps.get(position);
  • info.activityInfo.packageName will return the unique package name. mApps is of type List<ResolveInfo> mApps.

  • .get(position) will return the item's position in the list view or grid view.

Thanks, Md Saifuddin

Upvotes: 2

denis.solonenko
denis.solonenko

Reputation: 11775

I believe that package name is unique for every application

Upvotes: 3

Umesh Kacha
Umesh Kacha

Reputation: 13686

The PackageInfo.sharedUserId field will show the user Id assigned in the manifest.

If you want two applications to have the same userId, so they can see each other's data and run in the same process, then assign them the same userId in the manifest:

android:sharedUserId="app1" The two packages with the same sharedUserId need to have the same signature too.

Upvotes: 1

Related Questions