@@ -77,7 +77,6 @@ public class DownloadWorker extends Worker implements MethodChannel.MethodCallHa
7777 public static final String ARG_IS_RESUME = "is_resume" ;
7878 public static final String ARG_SHOW_NOTIFICATION = "show_notification" ;
7979 public static final String ARG_OPEN_FILE_FROM_NOTIFICATION = "open_file_from_notification" ;
80- public static final String ARG_NOTIFICATION_TITLE = "notification_title" ;
8180 public static final String ARG_CALLBACK_HANDLE = "callback_handle" ;
8281 public static final String ARG_DEBUG = "debug" ;
8382 public static final String ARG_STEP = "step" ;
@@ -166,11 +165,10 @@ public void onStopped() {
166165
167166 String url = getInputData ().getString (ARG_URL );
168167 String filename = getInputData ().getString (ARG_FILE_NAME );
169- String notificationTitle = getInputData ().getString (ARG_NOTIFICATION_TITLE );
170168
171169 DownloadTask task = taskDao .loadTask (getId ().toString ());
172170 if (task != null && task .status == DownloadStatus .ENQUEUED ) {
173- updateNotification (context , filename == null ? url : filename , DownloadStatus .CANCELED , -1 , null , true , notificationTitle );
171+ updateNotification (context , filename == null ? url : filename , DownloadStatus .CANCELED , -1 , null , true );
174172 taskDao .updateTask (getId ().toString (), DownloadStatus .CANCELED , lastProgress );
175173 }
176174 }
@@ -210,32 +208,31 @@ public Result doWork() {
210208
211209 showNotification = getInputData ().getBoolean (ARG_SHOW_NOTIFICATION , false );
212210 clickToOpenDownloadedFile = getInputData ().getBoolean (ARG_OPEN_FILE_FROM_NOTIFICATION , false );
213- String notificationTitle = getInputData ().getString (ARG_NOTIFICATION_TITLE );
214211 saveInPublicStorage = getInputData ().getBoolean (ARG_SAVE_IN_PUBLIC_STORAGE , false );
215212
216213 primaryId = task .primaryId ;
217214
218215 setupNotification (context );
219216
220- updateNotification (context , filename == null ? url : filename , DownloadStatus .RUNNING , task .progress , null , false , notificationTitle );
217+ updateNotification (context , filename == null ? url : filename , DownloadStatus .RUNNING , task .progress , null , false );
221218 taskDao .updateTask (getId ().toString (), DownloadStatus .RUNNING , task .progress );
222219
223220 //automatic resume for partial files. (if the workmanager unexpectedly quited in background)
224221 String saveFilePath = savedDir + File .separator + filename ;
225222 File partialFile = new File (saveFilePath );
226223 if (partialFile .exists ()) {
227224 isResume = true ;
228- log ("exists file for " + filename + "automatic resuming..." );
225+ log ("exists file for " + filename + "automatic resuming..." );
229226 }
230227
231228 try {
232- downloadFile (context , url , savedDir , filename , notificationTitle , headers , isResume );
229+ downloadFile (context , url , savedDir , filename , headers , isResume );
233230 cleanUp ();
234231 dbHelper = null ;
235232 taskDao = null ;
236233 return Result .success ();
237234 } catch (Exception e ) {
238- updateNotification (context , filename == null ? url : filename , DownloadStatus .FAILED , -1 , null , true , notificationTitle );
235+ updateNotification (context , filename == null ? url : filename , DownloadStatus .FAILED , -1 , null , true );
239236 taskDao .updateTask (getId ().toString (), DownloadStatus .FAILED , lastProgress );
240237 e .printStackTrace ();
241238 dbHelper = null ;
@@ -249,7 +246,7 @@ private void setupHeaders(HttpURLConnection conn, String headers) {
249246 log ("Headers = " + headers );
250247 try {
251248 JSONObject json = new JSONObject (headers );
252- for (Iterator <String > it = json .keys (); it .hasNext ();) {
249+ for (Iterator <String > it = json .keys (); it .hasNext (); ) {
253250 String key = it .next ();
254251 conn .setRequestProperty (key , json .getString (key ));
255252 }
@@ -272,7 +269,7 @@ private long setupPartialDownloadedDataHeader(HttpURLConnection conn, String fil
272269 return downloadedBytes ;
273270 }
274271
275- private void downloadFile (Context context , String fileURL , String savedDir , String filename , String notificationTitle , String headers , boolean isResume ) throws IOException {
272+ private void downloadFile (Context context , String fileURL , String savedDir , String filename , String headers , boolean isResume ) throws IOException {
276273 String url = fileURL ;
277274 URL resourceUrl , base , next ;
278275 Map <String , Integer > visited ;
@@ -301,14 +298,14 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
301298
302299 resourceUrl = new URL (url );
303300
304- if (ignoreSsl ) {
301+ if (ignoreSsl ) {
305302 trustAllHosts ();
306303 if (resourceUrl .getProtocol ().toLowerCase ().equals ("https" )) {
307- HttpsURLConnection https = (HttpsURLConnection ) resourceUrl .openConnection ();
304+ HttpsURLConnection https = (HttpsURLConnection )resourceUrl .openConnection ();
308305 https .setHostnameVerifier (DO_NOT_VERIFY );
309306 httpConn = https ;
310307 } else {
311- httpConn = (HttpURLConnection ) resourceUrl .openConnection ();
308+ httpConn = (HttpURLConnection )resourceUrl .openConnection ();
312309 }
313310 } else {
314311 httpConn = (HttpsURLConnection ) resourceUrl .openConnection ();
@@ -317,7 +314,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
317314 log ("Open connection to " + url );
318315 httpConn .setConnectTimeout (15000 );
319316 httpConn .setReadTimeout (15000 );
320- httpConn .setInstanceFollowRedirects (false ); // Make the logic below easier to detect redirections
317+ httpConn .setInstanceFollowRedirects (false ); // Make the logic below easier to detect redirections
321318 httpConn .setRequestProperty ("User-Agent" , "Mozilla/5.0..." );
322319
323320 // setup request headers if it is set
@@ -338,7 +335,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
338335 location = httpConn .getHeaderField ("Location" );
339336 log ("Location = " + location );
340337 base = new URL (url );
341- next = new URL (base , location ); // Deal with relative URLs
338+ next = new URL (base , location ); // Deal with relative URLs
342339 url = next .toExternalForm ();
343340 log ("New url: " + url );
344341 continue ;
@@ -384,6 +381,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
384381 // opens input stream from the HTTP connection
385382 inputStream = httpConn .getInputStream ();
386383
384+
387385 String savedFilePath ;
388386 // opens an output stream to save into file
389387 // there are two case:
@@ -427,7 +425,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
427425 // a new bunch of data fetched and a notification sent
428426 taskDao .updateTask (getId ().toString (), DownloadStatus .RUNNING , progress );
429427
430- updateNotification (context , filename , DownloadStatus .RUNNING , progress , null , false , notificationTitle );
428+ updateNotification (context , filename , DownloadStatus .RUNNING , progress , null , false );
431429 }
432430 }
433431
@@ -457,19 +455,19 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
457455 }
458456 }
459457 taskDao .updateTask (getId ().toString (), status , progress );
460- updateNotification (context , filename , status , progress , pendingIntent , true , notificationTitle );
458+ updateNotification (context , filename , status , progress , pendingIntent , true );
461459
462460 log (isStopped () ? "Download canceled" : "File downloaded" );
463461 } else {
464462 DownloadTask task = taskDao .loadTask (getId ().toString ());
465463 int status = isStopped () ? (task .resumable ? DownloadStatus .PAUSED : DownloadStatus .CANCELED ) : DownloadStatus .FAILED ;
466464 taskDao .updateTask (getId ().toString (), status , lastProgress );
467- updateNotification (context , filename == null ? fileURL : filename , status , -1 , null , true , notificationTitle );
465+ updateNotification (context , filename == null ? fileURL : filename , status , -1 , null , true );
468466 log (isStopped () ? "Download canceled" : "Server replied HTTP code: " + responseCode );
469467 }
470468 } catch (IOException e ) {
471469 taskDao .updateTask (getId ().toString (), DownloadStatus .FAILED , lastProgress );
472- updateNotification (context , filename == null ? fileURL : filename , DownloadStatus .FAILED , -1 , null , true , notificationTitle );
470+ updateNotification (context , filename == null ? fileURL : filename , DownloadStatus .FAILED , -1 , null , true );
473471 e .printStackTrace ();
474472 } finally {
475473 if (outputStream != null ) {
@@ -538,10 +536,11 @@ private Uri createFileInPublicDownloadsDir(String filename, String mimeType) {
538536 private String getMediaStoreEntryPathApi29 (Uri uri ) {
539537 try (Cursor cursor = getApplicationContext ().getContentResolver ().query (
540538 uri ,
541- new String [] { MediaStore .Files .FileColumns .DATA },
539+ new String []{ MediaStore .Files .FileColumns .DATA },
542540 null ,
543541 null ,
544- null )) {
542+ null
543+ )) {
545544 if (cursor == null )
546545 return null ;
547546 if (!cursor .moveToFirst ())
@@ -557,8 +556,8 @@ private String getMediaStoreEntryPathApi29(Uri uri) {
557556 void scanFilePath (String path , String mimeType , CallbackUri callback ) {
558557 MediaScannerConnection .scanFile (
559558 getApplicationContext (),
560- new String [] { path },
561- new String [] { mimeType },
559+ new String []{ path },
560+ new String []{ mimeType },
562561 (path1 , uri ) -> callback .invoke (uri ));
563562 }
564563
@@ -609,14 +608,14 @@ private void setupNotification(Context context) {
609608 }
610609 }
611610
612- private void updateNotification (Context context , String title , int status , int progress , PendingIntent intent , boolean finalize , String notificationTitle ) {
611+ private void updateNotification (Context context , String title , int status , int progress , PendingIntent intent , boolean finalize ) {
613612 sendUpdateProcessEvent (status , progress );
614613
615614 // Show the notification
616615 if (showNotification ) {
617616 // Create the notification
618617 NotificationCompat .Builder builder = new NotificationCompat .Builder (context , CHANNEL_ID ).
619- setContentTitle (notificationTitle == null ? title : notificationTitle )
618+ setContentTitle (title )
620619 .setContentIntent (intent )
621620 .setOnlyAlertOnce (true )
622621 .setAutoCancel (true )
0 commit comments