summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/browser/BrowserActivity.java3
-rw-r--r--src/com/android/browser/OpenDownloadReceiver.java48
2 files changed, 12 insertions, 39 deletions
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 @@ public class BrowserActivity extends Activity
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 @@ public class OpenDownloadReceiver extends BroadcastReceiver {
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);
}
}