Get Currently Active User in Android

筅森魡賤 提交于 2019-12-23 20:32:16

问题


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 :(


回答1:


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.



来源:https://stackoverflow.com/questions/18854825/get-currently-active-user-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!