问题
Is there any way to add automatically account just after installation my application (but it was not started yet).
回答1:
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.
回答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);
}
来源:https://stackoverflow.com/questions/8758830/autoadd-account-after-application-is-installed