Is there any way to add automatically account just after installation my application (but it was not started yet).
Asked
Active
Viewed 499 times
-1
-
1YOu need to be more specific as what you are trying to do. http://blog.stackoverflow.com/2010/10/asking-better-questions/ – coder_For_Life22 Jan 06 '12 at 13:53
2 Answers
3
It is impossible to do anything "just after installation my application (but it was not started yet)". When the user launches your main activity, you can set up the account or whatever other sort of first-time event you want.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
2
Here is a peace of code which automatically activates account
final AccountManager accountManager = AccountManager.get(this);
String authority = getString(R.string.acc_authority);
String accountType = getString(R.string.acc_name);
String accountName = getString(R.string.app_name);
Account[] existingAccs = accountManager.getAccountsByType(accountType);
if (existingAccs.length > 0) {
return;
}
Account account = new Account(accountName, accountType);
if (accountManager.addAccountExplicitly(account, null, null)) {
ContentResolver.setIsSyncable(account, authority, 1);
ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.requestSync(account, authority, new Bundle());
ContentResolver.addPeriodicSync(account, authority, new Bundle(), 60*10);
}

Solvek
- 5,158
- 5
- 41
- 64
-
Currently after install my app and login I have to go to Accounts to enable the sync. By default it's off. Is there any way that I can set default on? – ray Jun 18 '13 at 17:57