I am trying to extend the SampleSync application. After I install the app, I can go to settings -> accounts & sync -> add account to add an account. However, if I want to check from my Application code and want to trigger AccountManager to add a new account directly, what should be the best way?
Asked
Active
Viewed 2,964 times
1
-
http://stackoverflow.com/a/25890770/3282461 [here](http://stackoverflow.com/a/25890770/3282461) the full solution with code. – Ankit Kumar Sep 17 '14 at 12:44
-
http://stackoverflow.com/a/25890770/3282461 see this... here is the full code and solution – Ankit Kumar Sep 17 '14 at 12:45
1 Answers
5
Ok, finally I got it working,
You can actually activate the AccountManager to add an account:
final AccountManager accountMgr = AccountManager.get(Main.this);
accountMgr.addAccount(Constants.ACCOUNT_TYPE, Constants.AUTHTOKEN_TYPE, null, null, Main.this, null, null);

Pratik Butani
- 60,504
- 58
- 273
- 437

Sajid
- 891
- 2
- 13
- 24
-
-
@chris, sorry I didn't put the full context. This code is in an anonymous inner class which sits in the Main.java class. From the inner class, you need to do Main.this to get a reference of the outer class. let me know if you need more details on this. – Sajid Mar 14 '11 at 02:10