Skip to content

Instantly share code, notes, and snippets.

@LOG-TAG
Forked from UweTrottmann/MyApp.java
Last active August 29, 2015 14:24
Show Gist options
  • Save LOG-TAG/a6fc616bd0fe706ff15e to your computer and use it in GitHub Desktop.
Save LOG-TAG/a6fc616bd0fe706ff15e to your computer and use it in GitHub Desktop.
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// set up a dummy account for syncing
AccountManager manager = AccountManager.get(this);
final Account account = new Account(MyAccountAuthenticator.ACCOUNT_NAME, getPackageName());
if (manager.addAccountExplicitly(account, null, null)) {
// Only change sync settings if it did not exist, yet
ContentResolver.setIsSyncable(account, MyAccountAuthenticator.CONTENT_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, MyAccountAuthenticator.CONTENT_AUTHORITY, true);
// Sync daily by default
ContentResolver.addPeriodicSync(account, MyAccountAuthenticator.CONTENT_AUTHORITY, new Bundle(), 24 * 60 * 60);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment