Android UserManager:检查用户是否为所有者(管理员) [英] Android UserManager: Check if user is owner (admin)

查看:82
本文介绍了Android UserManager:检查用户是否为所有者(管理员)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为具有多用户功能的平板电脑开发具有最新Android版本(4.2.1 API级别17)的应用.

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?

我通读了UserManager和UserHandle API文档,但是找不到允许我检查的函数.

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?

推荐答案

类似但无反省:

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;
}

这篇关于Android UserManager:检查用户是否为所有者(管理员)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆