@@ -67,7 +67,7 @@ public static final UpdateChecker getInstance(Context ctx)
67
67
* new updates when connected to the internet.
68
68
* Default is false.
69
69
*
70
- *@param autoRun
70
+ *@param autoRun - Default is false
71
71
*@return UpdateChecker.class
72
72
*/
73
73
public UpdateChecker shouldAutoRun (boolean autoRun )
@@ -84,7 +84,7 @@ public UpdateChecker shouldAutoRun(boolean autoRun)
84
84
* The url where the new info of the app
85
85
* will be read to.
86
86
*
87
- *@param updateLogsUrl
87
+ *@param updateLogsUrl - The url of the json-encoded info of the new update
88
88
*@return UpdateChecker.class
89
89
*/
90
90
public UpdateChecker setUpdateLogsUrl (String updateLogsUrl )
@@ -98,7 +98,7 @@ public UpdateChecker setUpdateLogsUrl(String updateLogsUrl)
98
98
* install the new app after it has been
99
99
* downloaded.
100
100
*
101
- *@param autoInstall
101
+ *@param autoInstall - Default is false
102
102
*@return UpdateChecker.class
103
103
*/
104
104
public UpdateChecker shouldAutoInstall (boolean autoInstall )
@@ -111,7 +111,7 @@ public UpdateChecker shouldAutoInstall(boolean autoInstall)
111
111
* Sets an OnUpdateDetectedListener, when a new update
112
112
* is detected, this listener will be triggered.
113
113
*
114
- *@param listener
114
+ *@param listener - The listener to be triggered
115
115
*@return UpdateChecker.class
116
116
*/
117
117
public UpdateChecker setOnUpdateDetectedListener (UpdateChecker .OnUpdateDetectedListener listener )
@@ -123,7 +123,7 @@ public UpdateChecker setOnUpdateDetectedListener(UpdateChecker.OnUpdateDetectedL
123
123
/*
124
124
* Sets a custom json reader to suit your needs
125
125
*
126
- *@param jsonReader
126
+ *@param jsonReader - A custom class that extends {com.cdph.app.json.JSONReader}
127
127
*@return UpdateChecker.class
128
128
*/
129
129
public <T extends JSONReader > UpdateChecker setJsonReader (T jsonReader )
@@ -153,7 +153,7 @@ public void runUpdateChecker()
153
153
/*
154
154
* Installs the application
155
155
*
156
- *@param filePath
156
+ *@param filePath - The path of the apk to be installed
157
157
*@return null
158
158
*/
159
159
public void installApp (String path )
@@ -190,6 +190,7 @@ public File downloadUpdate(String url)
190
190
file = down .execute (url ).get ();
191
191
} catch (Exception e ) {
192
192
e .printStackTrace ();
193
+ Toast .makeText (ctx , String .format ("[ERROR]: %s" , e .getMessage ()), Toast .LENGTH_LONG ).show ();
193
194
}
194
195
195
196
return file ;
@@ -229,9 +230,6 @@ protected void onPreExecute()
229
230
{
230
231
super .onPreExecute ();
231
232
232
- if (jsonReader == null )
233
- jsonReader = new JSONReader ();
234
-
235
233
dlg = new ProgressDialog (ctx );
236
234
dlg .setCancelable (false );
237
235
dlg .setCanceledOnTouchOutside (false );
@@ -294,17 +292,18 @@ protected void onPostExecute(NewUpdateInfo result)
294
292
if (ctx .getPackageManager ().getPackageInfo (ctx .getPackageName (), 0 ).versionCode < result .app_version )
295
293
listener .onUpdateDetected (result , autoInstall );
296
294
else
297
- Toast .makeText (ctx , errMsg , Toast .LENGTH_LONG ).show ();
295
+ Toast .makeText (ctx , String . format ( "[ERROR]: %s" , errMsg ) , Toast .LENGTH_LONG ).show ();
298
296
} catch (Exception e ) {
299
297
e .printStackTrace ();
300
- Toast .makeText (ctx , e .getMessage (), Toast .LENGTH_LONG ).show ();
298
+ Toast .makeText (ctx , String . format ( "[ERROR]: %s" , e .getMessage () ), Toast .LENGTH_LONG ).show ();
301
299
}
302
300
}
303
301
}
304
302
305
303
private static final class TaskDownloadUpdate extends AsyncTask <String , Void , File >
306
304
{
307
305
private ProgressDialog dlg ;
306
+ private String errMsg ;
308
307
309
308
@ Override
310
309
protected void onPreExecute ()
@@ -361,6 +360,7 @@ protected File doInBackground(String[] params)
361
360
}
362
361
} catch (Exception e ) {
363
362
e .printStackTrace ();
363
+ errMsg += e .getMessage ();
364
364
}
365
365
366
366
return file ;
@@ -373,6 +373,9 @@ protected void onPostExecute(File result)
373
373
374
374
if (dlg != null )
375
375
dlg .dismiss ();
376
+
377
+ if (errMsg != null )
378
+ Toast .makeText (ctx , String .format ("[ERROR]: %s" , errMsg ), Toast .LENGTH_LONG ).show ();
376
379
}
377
380
}
378
381
0 commit comments