From 1d88aa02955a2579e38f6aeea56ec737a0310d62 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Thu, 4 Nov 2010 18:16:10 -0700 Subject: 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 --- src/com/android/browser/OpenDownloadReceiver.java | 48 +++++------------------ 1 file changed, 9 insertions(+), 39 deletions(-) (limited to 'src/com/android/browser/OpenDownloadReceiver.java') 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); } } -- cgit v1.1