Fixed automatic synchronization on application upgrade
This commit is contained in:
parent
df54a9edb3
commit
fc63bd346c
|
@ -278,8 +278,8 @@ public class SWADMain extends MenuExpandableListActivity {
|
||||||
lastVersion = prefs.getLastVersion();
|
lastVersion = prefs.getLastVersion();
|
||||||
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
||||||
dbHelper.initializeDB();
|
dbHelper.initializeDB();
|
||||||
//lastVersion = 55;
|
//lastVersion = 56;
|
||||||
//currentVersion = 56;
|
//currentVersion = 57;
|
||||||
|
|
||||||
//If this is the first run, show configuration dialog
|
//If this is the first run, show configuration dialog
|
||||||
if (lastVersion == 0) {
|
if (lastVersion == 0) {
|
||||||
|
@ -319,6 +319,7 @@ public class SWADMain extends MenuExpandableListActivity {
|
||||||
if(Preferences.isSyncEnabled()) {
|
if(Preferences.isSyncEnabled()) {
|
||||||
activity = new Intent(getBaseContext(), AccountAuthenticator.class);
|
activity = new Intent(getBaseContext(), AccountAuthenticator.class);
|
||||||
startActivity(activity);
|
startActivity(activity);
|
||||||
|
SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, this);
|
||||||
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.valueOf(prefs.getSyncTime()), this);
|
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.valueOf(prefs.getSyncTime()), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,17 +59,17 @@ public class SyncUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePeriodicSync(String authority, Bundle extras, Context context) {
|
public static void removePeriodicSync(String authority, Bundle extras, Context context) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 8) {
|
if (android.os.Build.VERSION.SDK_INT < 8) {
|
||||||
AccountManager am = AccountManager.get(context);
|
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
Account[] accounts = am.getAccountsByType(Constants.ACCOUNT_TYPE);
|
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) {
|
for (Account a : accounts) {
|
||||||
ContentResolver.removePeriodicSync(a, authority, extras);
|
ContentResolver.removePeriodicSync(a, authority, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
||||||
PendingIntent operation = PeriodicSyncReceiver.createPendingIntent(context, authority, extras);
|
|
||||||
manager.cancel(operation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user