Android UserManager: Check if User is Owner (Admin)

androidandroid-4.2-jelly-bean

Im developing an app with the latest android version (4.2.1 API-Level 17) for tablets with multiuser capabilities.

I want to restrict certain features (like the access to the app preferences) to the owner of the tablet (that is the user who can add and remove other user accounts)

is there any way i can find out if the current user is the owner?

i read through the UserManager and UserHandle API docs but couldn't find a function that allows me to check for it.

have i missed something or is there another way to do that?

Best Answer

Similar but without reflection:

static boolean isAdminUser(Context context)
{
    UserHandle uh = Process.myUserHandle();
    UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    if(null != um)
    {
        long userSerialNumber = um.getSerialNumberForUser(uh);
        Log.d(TAG, "userSerialNumber = " + userSerialNumber);
        return 0 == userSerialNumber;
    }
    else
        return false;
}
Related Question