Skip to content

Instantly share code, notes, and snippets.

@aleksi-niiranen
Created September 26, 2012 12:57
Show Gist options
  • Save aleksi-niiranen/3787862 to your computer and use it in GitHub Desktop.
Save aleksi-niiranen/3787862 to your computer and use it in GitHub Desktop.
Android sync provider
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,
String[] requiredFeatures, Bundle options) throws NetworkErrorException {
Bundle reply = new Bundle();
Account account = new Account("LunchBuddy", "com.blogspot.fwfaill.lunchbuddy.account");
AccountManager am = AccountManager.get(mContext);
boolean accountCreated = am.addAccountExplicitly(account, null, null);
if (accountCreated) {
reply.putString(AccountManager.KEY_ACCOUNT_NAME, "LunchBuddy");
reply.putString(AccountManager.KEY_ACCOUNT_TYPE, "com.blogspot.fwfaill.lunchbuddy.account");
}
return reply;
}
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.blogspot.fwfaill.lunchbuddy.account");
if (accounts.length < 1) {
Account account = new Account("LunchBuddy", "com.blogspot.fwfaill.lunchbuddy.account");
am.addAccountExplicitly(account, null, null);
ContentResolver.setIsSyncable(account, "com.blogspot.fwfaill.provider.LunchBuddy", 1);
ContentResolver.setSyncAutomatically(account, "com.blogspot.fwfaill.provider.LunchBuddy", true);
ContentResolver.addPeriodicSync(account, "com.blogspot.fwfaill.provider.LunchBuddy", new Bundle(), SYNC_FREQUENCY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment