2017年12月25日 星期一

Get the user id (Check if the user is owner)

Reference:
https://stackoverflow.com/questions/14749504/android-usermanager-check-if-user-is-owner-admin
http://blog.csdn.net/zhanglianyu00/article/details/50238447
http://blog.csdn.net/zhanglianyu00/article/details/50253187
http://gityuan.com/2016/11/20/user_manager/


Code snippet:
public static long getUserId(Context context){
    UserHandle uh = Process.myUserHandle();
    UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    long userSerialNumber = -1;
    if(null != um) {
        userSerialNumber = um.getSerialNumberForUser(uh);
    }
    return userSerialNumber;
}

沒有留言: