geek919
geek919

Reputation: 357

How to fetch users added in Android devices?

I want to fetch names of the user account's added in android device programmatically. For details go through the attached below image

enter image description here

I have tried below code

 AccountManager am = AccountManager.get(getActivity()); // "this" references the current Context
      //  Account[] accounts = am.getAccounts();
        Account[] accounts =am.getAccountsByType("com.google");
        if (accounts.length > 0) {
            name = accounts[0].name;
        } else {
            name = getActivity().getResources().getString(R.string.app_name);
        }

Upvotes: 1

Views: 118

Answers (1)

TheWanderer
TheWanderer

Reputation: 17844

I believe you want DevicePolicyManager#getSecondaryUsers().

You will need to have Device Administrator access: https://developer.android.com/guide/topics/admin/device-admin

Upvotes: 1

Related Questions