问题描述
我正在寻找一种获取Android当前活跃用户的方法.我正在构建一个系统应用程序,以便可以使用隐藏方法,但具体来说,它必须是当前的ACTIVE用户,而不是给定进程的用户.
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.
例如,如果您使用ADB安装应用,则该过程将表明用户ID是所有者.这意味着UserHandle.myUserId()无法满足我的需求:(
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 :(
推荐答案
所以我找到了一种完全可以满足我需要的方法.在ActivityManager中有一个静态方法被隐藏(因此您需要做一些魔术才能访问它),但是在这里是:
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();
仅此而已.
这篇关于在Android中获取当前的活动用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!