Reputation: 357
I want to fetch names of the user account's added in android device programmatically. For details go through the attached below image
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
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