Addresses #80. Caveat: I am not an Android developer. This code comes from a fork of the original RN WebView that we have been using in production for some time, so all credit goes to @Oblongmana: https://github.com/Oblongmana/react-native-webview-file-upload-android. Setting up a DownloadManager for the WebView is pretty straightforward, as is adding any known cookies to the request. Most of the complication comes from the requirement after SDK 23 to ask the user for the WRITE_EXTERNAL_STORAGE permission. Unfortunately there is no mechanism to suspend the download request until permission is resolved so this code stores off the request and sets up a listener that enqueues the download once permissions are resolved so the user experience is really nice. I didn't see anything in the way of tests or documentation that needs to be added for this change, so let me know if I missed anything. Thanks!
|
|
||
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
|
4 |
|
|
4 |
|
5 |
|
5 |
|
6 |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
6 |
|
11 |
|
7 |
|
12 |
|
8 |
|
13 |
|
|
|
||
21 |
|
26 |
|
22 |
|
27 |
|
23 |
|
28 |
|
|
29 |
|
|
24 |
|
30 |
|
25 |
|
31 |
|
26 |
|
32 |
|
27 |
|
33 |
|
28 |
|
34 |
|
|
35 |
|
|
29 |
|
36 |
|
30 |
|
37 |
|
|
38 |
|
|
31 |
|
39 |
|
32 |
|
40 |
|
33 |
|
41 |
|
34 |
|
42 |
|
35 |
|
43 |
|
36 |
|
44 |
|
|
45 |
|
|
37 |
|
46 |
|
38 |
|
47 |
|
39 |
|
48 |
|
|
|
||
446 |
|
455 |
|
447 |
|
456 |
|
448 |
|
457 |
|
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
|
462 |
|
|
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
|
|
|
471 |
|
|
|
472 |
|
|
|
473 |
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
|
|
|
486 |
|
|
|
487 |
|
|
|
488 |
|
|
|
489 |
|
|
|
490 |
|
|
|
491 |
|
|
|
492 |
|
|
|
493 |
|
|
|
494 |
|
|
|
495 |
|
|
|
496 |
|
|
|
497 |
|
|
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
449 |
|
505 |
|
450 |
|
506 |
|
451 |
|
507 |
|
|
|
||
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
|
4 |
|
|
4 |
|
5 |
|
|
6 |
|
|
|
7 |
|
|
5 |
|
8 |
|
|
9 |
|
|
6 |
|
10 |
|
7 |
|
11 |
|
8 |
|
12 |
|
9 |
|
13 |
|
10 |
|
14 |
|
11 |
|
15 |
|
|
16 |
|
|
12 |
|
17 |
|
13 |
|
18 |
|
14 |
|
19 |
|
15 |
|
20 |
|
|
21 |
|
|
16 |
|
22 |
|
17 |
|
23 |
|
18 |
|
24 |
|
19 |
|
25 |
|
20 |
|
26 |
|
21 |
|
27 |
|
|
28 |
|
|
|
29 |
|
|
22 |
|
30 |
|
23 |
|
31 |
|
24 |
|
32 |
|
|
|
||
38 |
|
46 |
|
39 |
|
47 |
|
40 |
|
48 |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
41 |
|
52 |
|
42 |
|
53 |
|
43 |
|
54 |
|
|
|
||
177 |
|
188 |
|
178 |
|
189 |
|
179 |
|
190 |
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
180 |
|
222 |
|
181 |
|
223 |
|
182 |
|
224 |
|
|
|
||
306 |
|
348 |
|
307 |
|
349 |
|
308 |
|
350 |
|
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
309 |
|
381 |
|
|
|
||
105 |
|
105 |
|
106 |
|
106 |
|
107 |
|
107 |
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|