@@ -127,13 +127,15 @@ public void run() {
127127 Uri uri = Uri .parse (url );
128128 DownloadManager .Request req = new DownloadManager .Request (uri );
129129 req .setNotificationVisibility (DownloadManager .Request .VISIBILITY_VISIBLE_NOTIFY_COMPLETED );
130-
131- if (options .addAndroidDownloads .hasKey ("title" )) {
130+ if (options .addAndroidDownloads .hasKey ("title" )) {
132131 req .setTitle (options .addAndroidDownloads .getString ("title" ));
133132 }
134- if (options .addAndroidDownloads .hasKey ("description" )) {
133+ if (options .addAndroidDownloads .hasKey ("description" )) {
135134 req .setDescription (options .addAndroidDownloads .getString ("description" ));
136135 }
136+ if (options .addAndroidDownloads .hasKey ("path" )) {
137+ req .setDestinationUri (Uri .parse ("file://" + options .addAndroidDownloads .getString ("path" )));
138+ }
137139 // set headers
138140 ReadableMapKeySetIterator it = headers .keySetIterator ();
139141 while (it .hasNextKey ()) {
@@ -558,14 +560,28 @@ public void onReceive(Context context, Intent intent) {
558560 String contentUri = c .getString (c .getColumnIndex (DownloadManager .COLUMN_LOCAL_URI ));
559561 Uri uri = Uri .parse (contentUri );
560562 Cursor cursor = appCtx .getContentResolver ().query (uri , new String []{android .provider .MediaStore .Images .ImageColumns .DATA }, null , null , null );
563+ // use default destination of DownloadManager
561564 if (cursor != null ) {
562565 cursor .moveToFirst ();
563566 String filePath = cursor .getString (0 );
564567 cursor .close ();
565568 this .callback .invoke (null , RNFetchBlobConst .RNFB_RESPONSE_PATH , filePath );
566569 }
567- else
568- this .callback .invoke (null , null , null );
570+ // custom destination
571+ else {
572+ if (options .addAndroidDownloads .hasKey ("path" )) {
573+ try {
574+ String customDest = options .addAndroidDownloads .getString ("path" );
575+ boolean exists = new File (customDest ).exists ();
576+ if (!exists )
577+ throw new Exception ("Download manager download failed, the file does not downloaded to destination." );
578+ callback .invoke (null , RNFetchBlobConst .RNFB_RESPONSE_PATH , customDest );
579+
580+ } catch (Exception ex ) {
581+ this .callback .invoke (ex .getLocalizedMessage (), null , null );
582+ }
583+ }
584+ }
569585 }
570586 }
571587 }
0 commit comments