- final String destFile = new File(new URL(downloadUrl).getFile())
- .getName();
- Log.d(LOG, "Downloading to: " + destFile);
-
- try {
- request.setDestinationInExternalFilesDir(getApplicationContext(), null, destFile);
- } catch (IllegalStateException e) {
- request.setDestinationUri(Uri.fromFile(new File(Environment
- .getExternalStorageDirectory(), destFile)));
- }
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
+ request.setDestinationUri(Uri.fromFile(destFilePath));
+ } catch (Exception e) {
+ }
+
+ try {
+ downloadManager.enqueue(request);
+ } catch (SecurityException e) {
+ request = new Request(Uri.parse(downloadUrl));
+ request.setTitle(destFile);
+ downloadManager.enqueue(request);