I am trying to force sync for all the accounts that show under sync options. This is the code i have tried so far which leads to crash. How can i trigger android to sync all accounts? I want the same effect as when the user is in the sync settings and clicks "sync all".
final String AUTHORITY = "com.example.android.datasync.provider";
AccountManager account_manager=AccountManager.get(this);
Account[] accounts = account_manager.getAccounts();
ContentResolver.setMasterSyncAutomatically(true);
for(int i=0;i<accounts.length;i++)
ContentResolver.requestSync(accounts[i], AUTHORITY, null);