2010-12-10 119 views
1

我正試圖擴展SampleSync應用程序。在我安裝應用程序後,我可以進入設置 - >賬戶&同步 - >添加賬戶添加一個賬戶。但是,如果我想從我的應用程序代碼中檢查並希望觸發AccountManager直接添加新帳戶,那麼最好的方法是什麼?如何觸發客戶經理從應用程序添加新帳戶

+0

http://stackoverflow.com/a/25890770/3282461 [這裏](http://stackoverflow.com/a/25890770/3282461)代碼的完整解決方案。 – Android 2014-09-17 12:44:20

+0

http://stackoverflow.com/a/25890770/3282461 看到這裏......這是完整的代碼和解決方案 – Android 2014-09-17 12:45:32

回答

5

好吧,我終於得到了它的工作,

實際上,你可以激活的AccountManager添加帳戶:

final AccountManager accountMgr = AccountManager.get(Main.this); 
accountMgr.addAccount(Constants.ACCOUNT_TYPE, Constants.AUTHTOKEN_TYPE, null, null, Main.this, null, null);