diff options
author | Leon Scroggins <scroggo@google.com> | 2010-10-22 15:06:59 -0400 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2010-10-27 10:31:11 -0400 |
commit | c6076533b489c17493640c14935324a30f582903 (patch) | |
tree | 01252ddbd00264d35af86451f57135b2166428e6 /src/com/android/browser/BrowserActivity.java | |
parent | 7d132b17c9dd1a816c68bf8505be2028691aaee3 (diff) | |
download | packages_apps_Browser-c6076533b489c17493640c14935324a30f582903.zip packages_apps_Browser-c6076533b489c17493640c14935324a30f582903.tar.gz packages_apps_Browser-c6076533b489c17493640c14935324a30f582903.tar.bz2 |
Use the new public API for DownloadManager.
Bug:3116742
Change-Id: I5d0d9a12e1bd601cf6a95198578ce8f9acd81372
Diffstat (limited to 'src/com/android/browser/BrowserActivity.java')
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 319ffad..2fe9e1b 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -3212,33 +3212,28 @@ public class BrowserActivity extends Activity return; } - // XXX: Have to use the old url since the cookies were stored using the - // old percent-encoded url. - String cookies = CookieManager.getInstance().getCookie(url); - - ContentValues values = new ContentValues(); - values.put(Downloads.Impl.COLUMN_URI, webAddress.toString()); - values.put(Downloads.Impl.COLUMN_COOKIE_DATA, cookies); - values.put(Downloads.Impl.COLUMN_USER_AGENT, userAgent); - values.put(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE, - getPackageName()); - values.put(Downloads.Impl.COLUMN_NOTIFICATION_CLASS, - OpenDownloadReceiver.class.getCanonicalName()); - values.put(Downloads.Impl.COLUMN_VISIBILITY, - Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimetype); - values.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, filename); - values.put(Downloads.Impl.COLUMN_DESCRIPTION, webAddress.getHost()); - if (contentLength > 0) { - values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, contentLength); - } + String addressString = webAddress.toString(); + Uri uri = Uri.parse(addressString); + DownloadManager.Request request = new DownloadManager.Request(uri); + request.setMimeType(mimetype); + request.setDestinationInExternalFilesDir(this, null, filename); + request.setDescription(webAddress.getHost()); if (mimetype == null) { + ContentValues values = new ContentValues(); + values.put(FetchUrlMimeType.URI, addressString); + // XXX: Have to use the old url since the cookies were stored using the + // old percent-encoded url. + String cookies = CookieManager.getInstance().getCookie(url); + values.put(FetchUrlMimeType.COOKIE_DATA, cookies); + values.put(FetchUrlMimeType.USER_AGENT, userAgent); + // We must have long pressed on a link or image to download it. We // are not sure of the mimetype in this case, so do a head request - new FetchUrlMimeType(this).execute(values); + new FetchUrlMimeType(this, request).execute(values); } else { - final Uri contentUri = - getContentResolver().insert(Downloads.Impl.CONTENT_URI, values); + DownloadManager manager + = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); + manager.enqueue(request); } Toast.makeText(this, R.string.download_pending, Toast.LENGTH_SHORT) .show(); |