j__m
j__m

Reputation: 9645

obtaining the user name of any user

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:

Please forgive the multi-part question, but:

Any insight appreciated.

Upvotes: 2

Views: 245

Answers (1)

Chintan Khetiya
Chintan Khetiya

Reputation: 16162

I have tried to search about it & can say it's not possible to get details of "Restricted Profile (User)".

In background when you try to read details for "Restricted Profile user" they are trying to change in database and throw SQLiteexception : delete then re-write existing database throws SQLiteReadOnlyDatabaseException on getWritableDatabase. due to this exception I don't think there is chance to read user name.

Without use your above code you can get directly call getUsername() of UserManager class.[API Level 17]

Upvotes: 1

Related Questions