1

I'm currently working on an app which is working with different profiles. To simplify the support process, I wan't to display currently active user within the app. According to this question: Get Currently Active User in Android this should be possible through:

ActivityManager.getCurrentUser()

Unfortunately the method is not available in Android O (SDK Version 27). The method is visible, but it's annotated by @hide which according to this answer: What does @hide mean in the Android source code? is not accessible. What other options do I have to the the currently active user?

Edit: What I'm talking about the current user detail. Assumption is you have two users on the same phone (i.e. private user + work profile user). To see my users, I can do the following:

> adb shell
> pm list users
> Users:
>  UserInfo{0:Jeff:13} running
>  UserInfo{10:Work profile:30} running

What I'm lookin for is the user id (0 or 10) in this example.

Lukas
  • 2,544
  • 2
  • 18
  • 33

1 Answers1

-1

When you say different profiles, it could have multiple meanings .I have listed each one below ( Also check here to learn more):

1) Different user for your app : You can store the data within you app in this case

2) Different user for the same phone : All users have to install the apps separately and all the apps data will be maintained separately for each user by the Android OS. ActivityManager.getCurrentUser() is a hidden api and meant to be used only by the system apps . So you cannot use this . This gives you information on the current user when multiple users are using the same phone .

3) Different Accounts (like gmail,fb etc) created by a user of the phone : Android maintain a central registry of the Accounts, to get details on that check AccountManager .

khetanrajesh
  • 300
  • 3
  • 13
  • I added additional information to the question (basically it's NR 2) – Lukas May 09 '18 at 14:08
  • Then it's not possible , because from app perspective it will be just a single user .Every user will have his own instance of the app. – khetanrajesh May 09 '18 at 14:23
  • Fine, I don't want to access other users data. But how can I get my user data (or in particular my id)? – Lukas May 09 '18 at 14:33