Android UserManager: Check if user is owner (admin)

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?


public boolean isCurrentUserOwner(Context context)
{
    try
    {
        Method getUserHandle = UserManager.class.getMethod("getUserHandle");
        int userHandle = (Integer) getUserHandle.invoke(context.getSystemService(Context.USER_SERVICE));
        return userHandle == 0;
    }
    catch (Exception ex)
    {
        return false;
    }
}



你可能感兴趣的:(android)