Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Currently Active User in Android

I'm looking for a way to get the current active user in Android. I'm building a system app so I can use hidden methods, but specifically it has to be the current ACTIVE user, and not the user for a given process.

For instance, if you install an app using ADB the process is going to say the user id is the owner. This means that UserHandle.myUserId() will not work for what I need :(

like image 439
Andrew T. Avatar asked Jul 28 '26 14:07

Andrew T.


1 Answers

So I found a method that does exactly what I need it to do. There is a static method in ActivityManager that is hidden (so you need to work some magic to have access to it) but here it is:

ActivityManager.getCurrentUser();

That's all there is to it.

like image 165
Andrew T. Avatar answered Jul 30 '26 06:07

Andrew T.