use new API (and not db) to access download notifications
instead of opening a cursor on the database to retrieve the file
to be opened when a notification is clicked on, use
DownloadManager's newly introduced API to get Uri and its
mimetype.
also, in BrowserActivity, when downloading a file,
allow it to be MediaScanner scannable and thus allow
media files to be displayed in Gallery.
by default, downloaded files DO NOT appear in Gallery
app any longer
depends on the following 3 CLs
I1f5dd734e394db0056579a3a0c26862fee27981e
I5c062ad6d1b58306044cee49ff3827e908d27fd9
Ia15000de4a66e8728b43fc53f428e098503b003b
Change-Id: Iad11a63fe0a7b8de188d1b6dc0445ccb96211fb2
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 799a8da..639a75b 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -3184,6 +3184,9 @@
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setMimeType(mimetype);
request.setDestinationInExternalFilesDir(this, null, filename);
+ // let this downloaded file be scanned by MediaScanner - so that it can show up
+ // in Gallery app, for example.
+ request.allowScanningByMediaScanner();
request.setDescription(webAddress.getHost());
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
diff --git a/src/com/android/browser/OpenDownloadReceiver.java b/src/com/android/browser/OpenDownloadReceiver.java
index 34cc6b9..02dba51 100644
--- a/src/com/android/browser/OpenDownloadReceiver.java
+++ b/src/com/android/browser/OpenDownloadReceiver.java
@@ -17,15 +17,10 @@
package com.android.browser;
import android.app.DownloadManager;
-import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.database.Cursor;
import android.net.Uri;
-import android.widget.Toast;
-
-import java.io.File;
/**
* This {@link BroadcastReceiver} handles clicks to notifications that
@@ -48,42 +43,17 @@
return;
}
long id = ids[0];
- DownloadManager.Query query = new DownloadManager.Query();
- query.setFilterById(id);
DownloadManager manager = (DownloadManager) context.getSystemService(
Context.DOWNLOAD_SERVICE);
- Cursor cursor = null;
- try {
- cursor = manager.query(query);
- if (cursor != null && cursor.moveToFirst()) {
- int status = cursor.getInt(cursor.getColumnIndexOrThrow(
- DownloadManager.COLUMN_STATUS));
- if (DownloadManager.STATUS_SUCCESSFUL == status) {
- Intent launchIntent = new Intent(Intent.ACTION_VIEW);
- int uriCol = cursor.getColumnIndexOrThrow(
- DownloadManager.COLUMN_LOCAL_FILENAME);
- String filename = cursor.getString(uriCol);
- Uri path = Uri.parse(filename);
- // If there is no scheme, then it must be a file
- if (path.getScheme() == null) {
- path = Uri.fromFile(new File(filename));
- }
- int typeCol = cursor.getColumnIndexOrThrow(
- DownloadManager.COLUMN_MEDIA_TYPE);
- String mimetype = cursor.getString(typeCol);
- launchIntent.setDataAndType(path, mimetype);
- launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(launchIntent);
- } else {
- // Open the downloads page
- openDownloadsPage(context);
- }
- }
- } catch (ActivityNotFoundException ex) {
- Toast.makeText(context, R.string.download_no_application_title,
- Toast.LENGTH_LONG).show();
- } finally {
- if (cursor != null) cursor.close();
+ Uri uri = manager.getUriForDownloadedFile(id);
+ if (uri == null) {
+ // Open the downloads page
+ openDownloadsPage(context);
+ } else {
+ Intent launchIntent = new Intent(Intent.ACTION_VIEW);
+ launchIntent.setDataAndType(uri, context.getContentResolver().getType(uri));
+ launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(launchIntent);
}
}