Prayansh Srivastava
Aug 11, 2017
7:53 pm

emailAccountPolicy.getAllEmailAccounts() returns null

Hey,

I am using the KNOX Standard SDK to retrieve all email accounts and delete a specific one from the list. I have followed the tutorial to activate the license and my app does activate (I checked via the EnterpriseLicenseManager.ACTION_LICENSE_STATUS lntent). But for some reason the emailAccountPolicy.getAllEmailAccounts() produces null even though there are email accounts on the device.

Here is the code I used with the KNOX APIs

EnterpriseDeviceManager edm = (EnterpriseDeviceManager) getSystemService(EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
EmailAccountPolicy emailAccountPolicy = edm.getEmailAccountPolicy();
Account[] accounts = emailAccountPolicy.getAllEmailAccounts();

I was able to retrieve the accounts via the native Android API. here is the code I used

AccountManager accMgr = AccountManager.get(CTMobileApplication.getContext());
Account[] accounts = accMgr.getAccounts();
Samuel V.Samsung SEAP Moderator
Aug 11, 2017
9:34 pm

Hi Prayansh,

Are the accounts you've mentioned set-up with the Email app? If you have accounts registered in settings but they haven't been set-up with the Email app, then EmailAccountPolicy.getAllEmailAccounts() will return null as it retrieves the accounts associated with the Email app. I can confirm this as I've tested it on Android M. Indeed, my Gmail accounts in settings are not returned until I register them with the Email app.

Please let me know if you have any further questions.

Best regards,

Samuel

Comments

Hi Samuel,

How can I then retrieve the accounts list, without associating them via the Email App?

Prayansh SrivastavaAug 11, 2017 at 9:36 pm
Samuel V.Samsung SEAP Moderator
Aug 11, 2017
9:42 pm

Hi Prayansh, 

There's no way to do it from a Samsung SDK standpoint because there's already a way to do it through Android as you've mentioned.

Prayansh Srivastava
Aug 11, 2017
9:51 pm

Hi Samuel,

Although I can get all the email accounts via the android API, I am not able to delete them with the Android APIs, and was hoping that the KNOX apis would be able to assist me in this task. 
Is there a way for me to delete a gmail account via the KNOX APIs?