Skip to content Skip to sidebar Skip to footer

How To Check If "multiple Users" Is Enabled

Is there a system setting table or API I can check to see if the 'Multiple users' setting is turned on in Settings -> System -> Advanced -> Multiple users? Thanks!

Solution 1:

After a few hours of searching, I found the answer by browsing /data/system/users/0 and looking through settings_system.xml, settings_secure.xml, and settings_global.xml. It turns out what I'm looking for is "user_switcher_enabled" in settings_global.xml.

Here's my code:

publicstaticbooleanisMultipleUsersEnabled(Context context) {
    try {
        intpref= Settings.Global.getInt(context.getContentResolver(), "user_switcher_enabled");
        returnpref== 1 && (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || UserManager.supportsMultipleUsers());
    } catch (Settings.SettingNotFoundException e) {
        Utils.logError(TAG, "user_switcher_enabled setting not found: " + e.toString());
        returnfalse;
    } 
}

The check for UserManager.supportsMultipleUsers() is probably not needed, but just in case the preference is somehow bogus on devices that don't actually support multiple users.

If there's anything you want to add to this answer, please comment below.

Solution 2:

For API level 24 and above, you can use the method UserManager.supportsMultipleUsers(), which returns whether the device supports multiple users in boolean.

Before API level 24, there are no methods to check this without system permissions. There can be a workaround, like getting the count of users using the method getUserCount(). Again this also needs android.permission.MANAGE_USERS permission.

Post a Comment for "How To Check If "multiple Users" Is Enabled"