I just created an Account for my app.
- The account is visible in settings
- I set syncable="true" in my XML
- I can perform a manual sync by pressing the settings -> onPerformSync is called
- I can perform a "code" sync by calling ContentResolver.requestSync -> onPerformSync is called
- And of course, yes, the sync is enabled in settings. I don't use any power saver.
I also followed all the steps from here: https://stackoverflow.com/a/5255360/327402
This is my code to get the sync by code
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType(ACCOUNT);
//Log.e("DEBUG", "Accounts: " + accounts.length);
if (accounts.length == 0) {
Account account = new Account(getString(R.string.app_name), ACCOUNT);
ContentResolver.setIsSyncable(account, AUTHORITY, 1);
ContentResolver.addPeriodicSync(account, AUTHORITY, new Bundle(), 7200);
ContentResolver.setSyncAutomatically(account, AUTHORITY, true);
if (am.addAccountExplicitly(account, "pass1", null))
Log.i("DEBUG", "account Created: " + account.name + ", " + account.type);
else
Log.i("DEBUG", "addAccountExplicitly returned false");
}
else{
ContentResolver.requestSync(accounts[0], AUTHORITY, new Bundle());// THIS IS WORKING!!!
}
}
So, everything looks correct and fine.
But unfortunately, I cannot get a periodic sync! When I open the settings, accounts, I see the account and the date and time is the time when I performed the sync by code, or manually.
Any idea on what I did wrong, or what I forgot?