23 |
public class CheckUpdates { |
public class CheckUpdates { |
24 |
public static long TIMESPAN_DAY = 24*60*60*1000; // one day |
public static long TIMESPAN_DAY = 24*60*60*1000; // one day |
25 |
final static String CHECKUPDATES = "CheckUpdates"; |
final static String CHECKUPDATES = "CheckUpdates"; |
26 |
|
final static String LASTCHECK = "lastcheck"; |
27 |
|
|
28 |
int versionCode; |
int versionCode; |
29 |
String versionName; |
String versionName; |
41 |
this.title = title; |
this.title = title; |
42 |
|
|
43 |
SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); |
SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); |
44 |
long lastCheck = prefs.getLong("lastcheck", 0); |
long lastCheck = prefs.getLong(LASTCHECK, 0); |
45 |
|
|
46 |
long now = System.currentTimeMillis(); //should i use android.os.SystemClock.elapsedRealtime() instead ? |
long now = System.currentTimeMillis(); //should i use android.os.SystemClock.elapsedRealtime() instead ? |
47 |
|
Log.i(CHECKUPDATES, "Now=" + now + ", lastCheck=" + lastCheck + ", lastCheck+timespan=" + (lastCheck + TIMESPAN_DAY) ); |
48 |
|
|
49 |
if ( now > (lastCheck+TIMESPAN_DAY) ){ |
if ( now > (lastCheck+TIMESPAN_DAY) ){ |
50 |
|
|
125 |
Log.i(CHECKUPDATES, "result=" + result + ", newestVersion" + newestVersion + ", versionCode=" + versionCode); |
Log.i(CHECKUPDATES, "result=" + result + ", newestVersion" + newestVersion + ", versionCode=" + versionCode); |
126 |
|
|
127 |
if (result == true) { |
if (result == true) { |
128 |
|
|
129 |
|
long now = System.currentTimeMillis(); |
130 |
|
SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); |
131 |
|
//when done write |
132 |
|
Editor edit = prefs.edit(); |
133 |
|
edit.putLong(LASTCHECK, now); |
134 |
|
edit.commit(); |
135 |
|
|
136 |
if (newestVersion > versionCode) { |
if (newestVersion > versionCode) { |
137 |
AlertDialog.Builder builder = new AlertDialog.Builder(context); |
AlertDialog.Builder builder = new AlertDialog.Builder(context); |
138 |
builder.setTitle(title); |
builder.setTitle(title); |
165 |
|
|
166 |
} |
} |
167 |
|
|
|
long now = System.currentTimeMillis(); |
|
|
SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); |
|
|
//when done write |
|
|
Editor edit = prefs.edit(); |
|
|
edit.putLong("lastCheck", now); |
|
|
edit.commit(); |
|
168 |
} |
} |
169 |
|
|
170 |
} |
} |