22 |
|
|
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 PREFS = "CheckUpdate"; |
final static String CHECKUPDATES = "CheckUpdates"; |
26 |
|
|
27 |
int versionCode; |
int versionCode; |
28 |
String versionName; |
String versionName; |
39 |
this.context = context; |
this.context = context; |
40 |
this.title = title; |
this.title = title; |
41 |
|
|
42 |
SharedPreferences prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); |
SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); |
43 |
long lastCheck = prefs.getLong("lastcheck", 0); |
long lastCheck = prefs.getLong("lastcheck", 0); |
44 |
|
|
45 |
long now = System.currentTimeMillis(); //should i use android.os.SystemClock.elapsedRealtime() instead ? |
long now = System.currentTimeMillis(); //should i use android.os.SystemClock.elapsedRealtime() instead ? |
63 |
task.execute(url); |
task.execute(url); |
64 |
|
|
65 |
|
|
|
|
|
66 |
} catch (NameNotFoundException e) { |
} catch (NameNotFoundException e) { |
67 |
e.printStackTrace(); |
Log.e(CHECKUPDATES, "NamingException", e); |
68 |
} |
} |
69 |
|
|
70 |
} |
} |
89 |
result = true; |
result = true; |
90 |
|
|
91 |
} catch (Exception e) { |
} catch (Exception e) { |
92 |
Log.e("CheckUpdates", "Check for " + packageName + " failed!", e); |
Log.e(CHECKUPDATES, "Check for " + packageName + " failed!", e); |
93 |
} |
} |
94 |
|
|
95 |
return null; |
return null; |
120 |
protected void onPostExecute(Void r) { |
protected void onPostExecute(Void r) { |
121 |
super.onPostExecute(r); |
super.onPostExecute(r); |
122 |
|
|
123 |
Log.i("CheckUpdates", "result=" + result + ", newestVersion" + newestVersion + ", versionCode=" + versionCode); |
Log.i(CHECKUPDATES, "result=" + result + ", newestVersion" + newestVersion + ", versionCode=" + versionCode); |
124 |
|
|
125 |
if (result == true) { |
if (result == true) { |
126 |
if (newestVersion > versionCode) { |
if (newestVersion > versionCode) { |
134 |
try { |
try { |
135 |
context.startActivity(i); |
context.startActivity(i); |
136 |
} catch (Exception e) { |
} catch (Exception e) { |
137 |
Log.e("CheckUpdates", "Activity launch failed", e); |
Log.e(CHECKUPDATES, "Activity launch failed", e); |
138 |
} |
} |
139 |
context = null; |
context = null; |
140 |
|
|
149 |
try { |
try { |
150 |
builder.show(); |
builder.show(); |
151 |
} catch (Exception e) { |
} catch (Exception e) { |
152 |
Log.e("CheckUpdates", "Builder.show failed", e); |
Log.e(CHECKUPDATES, "Builder.show failed", e); |
153 |
} |
} |
154 |
|
|
155 |
|
|
156 |
} |
} |
157 |
|
|
158 |
long now = System.currentTimeMillis(); |
long now = System.currentTimeMillis(); |
159 |
SharedPreferences prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); |
SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); |
160 |
//when done write |
//when done write |
161 |
Editor edit = prefs.edit(); |
Editor edit = prefs.edit(); |
162 |
edit.putLong("lastCheck", now); |
edit.putLong("lastCheck", now); |