I am currently using the following code to obtain the current user name:
String username;
{
Cursor c = ctx.getContentResolver().query(Profile.CONTENT_URI,
new String[]{Profile.DISPLAY_NAME}, null, null, null);
if (c.getCount() > 0)
{
c.moveToFirst();
username = c.getString(0);
}
On my test device (Samsung Galaxy Tab Pro), with the correct permissions, this works well for the "owner" user, as well as other non-restricted users. However, things seem to fall apart for limited user profiles:
- The code always returns zero cursor rows. I had hoped that enabling access to the Contacts app would allow it to work, but that has no effect.
- At any rate, unlike non-limited profiles, the profile of the limited user account does not seem to be connected to the name displayed on the lock screen, so even if I could get this code to work I'm not sure how useful it would be.
Please forgive the multi-part question, but:
- Is this a peculiarity of the Samsung tablet, or is this behavior consistent across devices?
- Is there any way to read the profile of a limited user?
- Is there a better way to obtain the current user name?
Any insight appreciated.