protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); SyncAccount = CreateSyncAccount(this); //This will set the auto-sync on for all applications if (!ContentResolver.MasterSyncAutomatically) { ContentResolver.MasterSyncAutomatically = true; } //Set the app auto sync On ContentResolver.SetSyncAutomatically(SyncAccount, AUTHORITY, true); ContentResolver.AddPeriodicSync(SyncAccount, AUTHORITY, Bundle.Empty, SYNC_INTERVAL); //This is to force sync on app start //var settingsBundle = new Bundle(); //settingsBundle.PutBoolean(ContentResolver.SyncExtrasManual, true); //settingsBundle.PutBoolean(ContentResolver.SyncExtrasExpedited, true); //ContentResolver.RequestSync(SyncAccount, AUTHORITY, new Bundle()); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App(new AndroidInitializer())); }
CustomContentResolver(Context context) { if (mAccount == null) { mAccount = CreateSyncAccount(context); } ContentResolver.AddPeriodicSync(mAccount, AUTHORITY, Bundle.Empty, SYNC_INTERVAL); ContentResolver.SetSyncAutomatically(mAccount, AUTHORITY, true); ContentResolver.MasterSyncAutomatically = true; }
/// <summary> /// Enables the periodic sync. /// </summary> void EnablePeriodicSync() { _account = AccountUtils.CreateSyncAccount(this); // set whether the account is syncable ContentResolver.SetIsSyncable(_account, AccountUtils.SyncAuthority, 1); // set to sync whenever it receives a network tickle ContentResolver.SetSyncAutomatically(_account, AccountUtils.SyncAuthority, true); // set to sync every x seconds ContentResolver.RemovePeriodicSync(_account, AccountUtils.SyncAuthority, Bundle.Empty); ContentResolver.AddPeriodicSync(_account, AccountUtils.SyncAuthority, Bundle.Empty, SyncFrequencySeconds); }
/// <summary> /// Helper method to schedule the sync adapter periodic execution /// </summary> public static void ConfigurePeriodicSync(Context context, int syncInterval, int flexTime) { var account = GetSyncAccount(context); var authority = context.GetString(Resource.String.content_authority); if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) { // we can enable inexact timers in our periodic sync var request = new SyncRequest.Builder(). SyncPeriodic(syncInterval, flexTime). SetSyncAdapter(account, authority). SetExtras(new Bundle()).Build(); ContentResolver.RequestSync(request); } else { ContentResolver.AddPeriodicSync(account, authority, new Bundle(), syncInterval); } }