Created
September 26, 2012 12:57
-
-
Save aleksi-niiranen/3787862 to your computer and use it in GitHub Desktop.
Android sync provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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