@@ -127,13 +127,15 @@ public void run() {
127
127
Uri uri = Uri .parse (url );
128
128
DownloadManager .Request req = new DownloadManager .Request (uri );
129
129
req .setNotificationVisibility (DownloadManager .Request .VISIBILITY_VISIBLE_NOTIFY_COMPLETED );
130
-
131
- if (options .addAndroidDownloads .hasKey ("title" )) {
130
+ if (options .addAndroidDownloads .hasKey ("title" )) {
132
131
req .setTitle (options .addAndroidDownloads .getString ("title" ));
133
132
}
134
- if (options .addAndroidDownloads .hasKey ("description" )) {
133
+ if (options .addAndroidDownloads .hasKey ("description" )) {
135
134
req .setDescription (options .addAndroidDownloads .getString ("description" ));
136
135
}
136
+ if (options .addAndroidDownloads .hasKey ("path" )) {
137
+ req .setDestinationUri (Uri .parse ("file://" + options .addAndroidDownloads .getString ("path" )));
138
+ }
137
139
// set headers
138
140
ReadableMapKeySetIterator it = headers .keySetIterator ();
139
141
while (it .hasNextKey ()) {
@@ -558,14 +560,28 @@ public void onReceive(Context context, Intent intent) {
558
560
String contentUri = c .getString (c .getColumnIndex (DownloadManager .COLUMN_LOCAL_URI ));
559
561
Uri uri = Uri .parse (contentUri );
560
562
Cursor cursor = appCtx .getContentResolver ().query (uri , new String []{android .provider .MediaStore .Images .ImageColumns .DATA }, null , null , null );
563
+ // use default destination of DownloadManager
561
564
if (cursor != null ) {
562
565
cursor .moveToFirst ();
563
566
String filePath = cursor .getString (0 );
564
567
cursor .close ();
565
568
this .callback .invoke (null , RNFetchBlobConst .RNFB_RESPONSE_PATH , filePath );
566
569
}
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
+ }
569
585
}
570
586
}
571
587
}
0 commit comments