7

In my project I need to access the Exchange accounts on the device, to change them.

I need to do it programatically , inside my application.

I have searched around but it does not seem that there is a way of doing such a thing.

Please any help or suggestion?


EDIT EDIT

To be more specific i need to: lists all email accounts on the device and allows the user to change settings for Exchange accounts:

*server address

*server port number

*SSL (on/off)

*accept all SSL certificates (on/off)

*account password

Lisa Anne
  • 4,482
  • 17
  • 83
  • 157

3 Answers3

1

Take a look at AccountManager (http://developer.android.com/reference/android/accounts/AccountManager.html)

You should be able to do something like this:

AccountManager accountManager = AccountManager.get(context);
Account[] accountList = accountManager.getAccounts();
for(Account account : accountList){
    accountManager.getUserData(account, AccountManager.KEY_USERDATA);
    accountManager.setUserData(account, AccountManager.KEY_USERDATA, "data");
}
Nyx
  • 2,233
  • 1
  • 12
  • 25
  • @LisaAnne perhaps I misunderstood your question. Doesn't the code above list all the accounts on your device? – Nyx Mar 28 '14 at 22:39
  • yes it does, thanks nyx, but what I need is a way to access the `*server address *server port number *SSL (on/off) *accept all SSL certificates (on/off) *account password` of the account, to be specific of an Microsoft Exchange Account – Lisa Anne Mar 28 '14 at 22:48
1

You can't modify the permissions/settings of an another exchange account (it gives you a security error). You only can create your own exchange account witch it will be included in your exchange accounts as yourAppName..

simas
  • 222
  • 1
  • 8
-1

Powershell is probably the tool that I would want to use to do this, but from devices it is tricky. Tools like AccountManager should assit with this as under the hood they are probably using Remote Powershell scripting. Alternatives that I can think of are:

  1. Create your own web service that you can execute powershell commands from, and have your app connect to that. This is a good primer that works for Exchange 2010 and 2013: http://forums.asp.net/t/1683553.aspx?Mailbox+creation+in+Exchange+Server+2010+using+ASP+Net+3+5+application
  2. Find a tool to execute remote powershell requests from the device direct. I have not tried this but this looks like a good thread to follow: http://social.technet.microsoft.com/Forums/windowsserver/en-US/bc1b417d-0388-486b-8742-305a48224a92/android-client-for-powershell-remote-scripting?forum=winserverpowershell

I personally already had web services hosted inside the domain that my app was using anyway (data source was in the domain), so I put my mailbox and AD user management service along side those, then the mobile apps made simple calls like CreateUser, EnableMailbox, CreateMailEnabledUser...

Chris Schaller
  • 13,704
  • 3
  • 43
  • 81