Fixed automatic synchronization on application upgrade

This commit is contained in:
Juan Miguel Boyero Corral 2013-11-30 20:24:15 +01:00
parent df54a9edb3
commit fc63bd346c
2 changed files with 13 additions and 12 deletions

View File

@ -278,8 +278,8 @@ public class SWADMain extends MenuExpandableListActivity {
lastVersion = prefs.getLastVersion();
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
dbHelper.initializeDB();
//lastVersion = 55;
//currentVersion = 56;
//lastVersion = 56;
//currentVersion = 57;
//If this is the first run, show configuration dialog
if (lastVersion == 0) {
@ -319,6 +319,7 @@ public class SWADMain extends MenuExpandableListActivity {
if(Preferences.isSyncEnabled()) {
activity = new Intent(getBaseContext(), AccountAuthenticator.class);
startActivity(activity);
SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, this);
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.valueOf(prefs.getSyncTime()), this);
}

View File

@ -59,17 +59,17 @@ public class SyncUtils {
}
public static void removePeriodicSync(String authority, Bundle extras, Context context) {
if (android.os.Build.VERSION.SDK_INT >= 8) {
AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccountsByType(Constants.ACCOUNT_TYPE);
if (android.os.Build.VERSION.SDK_INT < 8) {
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent operation = PeriodicSyncReceiver.createPendingIntent(context, authority, extras);
manager.cancel(operation);
} else {
AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccountsByType(Constants.ACCOUNT_TYPE);
for (Account a : accounts) {
ContentResolver.removePeriodicSync(a, authority, extras);
}
for (Account a : accounts) {
ContentResolver.removePeriodicSync(a, authority, extras);
}
}
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent operation = PeriodicSyncReceiver.createPendingIntent(context, authority, extras);
manager.cancel(operation);
}
}