|
@@ -8,6 +8,7 @@ import android.content.pm.ActivityInfo;
|
8
|
8
|
import android.content.pm.PackageManager;
|
9
|
9
|
import android.graphics.Bitmap;
|
10
|
10
|
import android.graphics.Color;
|
|
11
|
+import java.lang.IllegalArgumentException;
|
11
|
12
|
import android.Manifest;
|
12
|
13
|
import android.net.http.SslError;
|
13
|
14
|
import android.net.Uri;
|
|
@@ -211,36 +212,40 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
211
|
212
|
|
212
|
213
|
RNCWebViewModule module = getModule(reactContext);
|
213
|
214
|
|
214
|
|
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
215
|
|
-
|
216
|
|
- String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
217
|
|
- String downloadMessage = "Downloading " + fileName;
|
218
|
|
-
|
219
|
|
- //Attempt to add cookie, if it exists
|
220
|
|
- URL urlObj = null;
|
221
|
215
|
try {
|
222
|
|
- urlObj = new URL(url);
|
223
|
|
- String baseUrl = urlObj.getProtocol() + "://" + urlObj.getHost();
|
224
|
|
- String cookie = CookieManager.getInstance().getCookie(baseUrl);
|
225
|
|
- request.addRequestHeader("Cookie", cookie);
|
226
|
|
- } catch (MalformedURLException e) {
|
227
|
|
- System.out.println("Error getting cookie for DownloadManager: " + e.toString());
|
228
|
|
- e.printStackTrace();
|
229
|
|
- }
|
|
216
|
+ DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
|
217
|
+
|
|
218
|
+ String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
|
219
|
+ String downloadMessage = "Downloading " + fileName;
|
|
220
|
+
|
|
221
|
+ //Attempt to add cookie, if it exists
|
|
222
|
+ URL urlObj = null;
|
|
223
|
+ try {
|
|
224
|
+ urlObj = new URL(url);
|
|
225
|
+ String baseUrl = urlObj.getProtocol() + "://" + urlObj.getHost();
|
|
226
|
+ String cookie = CookieManager.getInstance().getCookie(baseUrl);
|
|
227
|
+ request.addRequestHeader("Cookie", cookie);
|
|
228
|
+ } catch (MalformedURLException e) {
|
|
229
|
+ System.out.println("Error getting cookie for DownloadManager: " + e.toString());
|
|
230
|
+ e.printStackTrace();
|
|
231
|
+ }
|
230
|
232
|
|
231
|
|
- //Finish setting up request
|
232
|
|
- request.addRequestHeader("User-Agent", userAgent);
|
233
|
|
- request.setTitle(fileName);
|
234
|
|
- request.setDescription(downloadMessage);
|
235
|
|
- request.allowScanningByMediaScanner();
|
236
|
|
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
237
|
|
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
|
|
233
|
+ //Finish setting up request
|
|
234
|
+ request.addRequestHeader("User-Agent", userAgent);
|
|
235
|
+ request.setTitle(fileName);
|
|
236
|
+ request.setDescription(downloadMessage);
|
|
237
|
+ request.allowScanningByMediaScanner();
|
|
238
|
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
239
|
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
|
238
|
240
|
|
239
|
|
- module.setDownloadRequest(request);
|
|
241
|
+ module.setDownloadRequest(request);
|
240
|
242
|
|
241
|
|
- if (module.grantFileDownloaderPermissions()) {
|
242
|
|
- module.downloadFile();
|
243
|
|
- }
|
|
243
|
+ if (module.grantFileDownloaderPermissions()) {
|
|
244
|
+ module.downloadFile();
|
|
245
|
+ }
|
|
246
|
+ } catch (IllegalArgumentException e) {
|
|
247
|
+ System.out.println("IllegalArgumentException: " + e.toString());
|
|
248
|
+ }
|
244
|
249
|
}
|
245
|
250
|
});
|
246
|
251
|
|