Is this possible to add and configure an exchange account programmaticaly

房东的猫 提交于 2019-12-08 07:37:33

问题


On android we can add an account manually through settings->Account&sync->add account->Corporate and then we fill the fields and add the account.

I want to do this programmatically. I searched on internet but did not find any way to do this.

I found two posts ( http://code.google.com/p/android/issues/detail?id=21233 AND Android How to add/configure Exchange setting programmatically? ), after which it looks like that it is not possible...But does any one know any way to do this?

We can programmatically open the screen settings->Account&sync->add account by intent Settings.ACTION_ADD_ACCOUNT. Can I somehow fill the fields too?

Is there any intent to do this? Or can I use account manager somehow?


回答1:


I did too encounter this problem and the only answer I ever got is NO for Android 3.0 and above, and NOT REALLY for 2.3 and lower.

  • For platform 2.3 and lower you can call intent with parameters for the Exchange account creation screen, so all fields will be filled.

    //Gingerbread and lower
    ComponentName localComponentName = new ComponentName("com.android.email", "com.android.email.activity.setup.AccountSetupBasics");
    Intent exchangeIntent = new Intent("android.intent.action.MAIN");
    exchangeIntent.putExtra("com.android.email.AccountSetupBasics.username", mUserName);
    exchangeIntent.putExtra("com.android.email.AccountSetupBasics.password", mPassword);
    exchangeIntent.putExtra("com.android.email.extra.eas_flow", true);
    exchangeIntent.setComponent(localComponentName);
    exchangeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    

    (This code is based on an answer i found on stack exchange but i cant find it again for reference)

    You must understand that this solution does not apply to devices that do not have the default eMail client.

    I consider this solution as a hack and not a real solution but this is what i'v found.

  • From HoneyComb and onward the exchange account creation screen was changed and it does not get those parameters any more from the intent, so this solution does not apply and i could not found any other way to do it.

  • Another solution that i have not implemented is to use a 3rd party email client which supply's needed API to create, delete or modify an exchange account

Hope i helped



来源:https://stackoverflow.com/questions/12404230/is-this-possible-to-add-and-configure-an-exchange-account-programmaticaly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!