-
-
Save ryanamaral/1edca2f7ba0c52c477cf to your computer and use it in GitHub Desktop.
Set up a dummy account for your Android SyncAdapter. Run this on app startup, e.g. in your Application classes onCreate().
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
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
I just want to create a simple account in my device