summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/OpenDownloadReceiver.java
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2010-04-19 16:53:49 -0400
committerLeon Scroggins <scroggo@google.com>2010-04-19 17:27:38 -0400
commita563d09392905140893d7a017dd63721577e1953 (patch)
treea35a610b5c7dd9f52c78dc619a6ce58835a62d92 /src/com/android/browser/OpenDownloadReceiver.java
parent8588d15a7c0b87049469fd80f9c53eb274cd837b (diff)
downloadandroid_packages_apps_Gello-a563d09392905140893d7a017dd63721577e1953.tar.gz
android_packages_apps_Gello-a563d09392905140893d7a017dd63721577e1953.tar.bz2
android_packages_apps_Gello-a563d09392905140893d7a017dd63721577e1953.zip
Click on notification for unfinished download, open downloads page.
BrowserActivity: Use OpenDownloadReceiver as class name, so that it will handle the notification from download manager. OpenDownloadReceiver: If the download is not complete, show the downloads page. Bug 2606772 Change-Id: Ifeeac0943650552c6da232cf98088bbf958fd403
Diffstat (limited to 'src/com/android/browser/OpenDownloadReceiver.java')
-rw-r--r--src/com/android/browser/OpenDownloadReceiver.java69
1 files changed, 42 insertions, 27 deletions
diff --git a/src/com/android/browser/OpenDownloadReceiver.java b/src/com/android/browser/OpenDownloadReceiver.java
index ad66c037..da53fb28 100644
--- a/src/com/android/browser/OpenDownloadReceiver.java
+++ b/src/com/android/browser/OpenDownloadReceiver.java
@@ -38,36 +38,51 @@ public class OpenDownloadReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
ContentResolver cr = context.getContentResolver();
Uri data = intent.getData();
- Cursor cursor = cr.query(data,
- new String[] { Downloads.Impl._ID, Downloads.Impl._DATA,
- Downloads.Impl.COLUMN_MIME_TYPE }, null, null, null);
- if (cursor.moveToFirst()) {
- String filename = cursor.getString(1);
- String mimetype = cursor.getString(2);
- String action = intent.getAction();
- if (Downloads.ACTION_NOTIFICATION_CLICKED.equals(action)) {
- Intent launchIntent = new Intent(Intent.ACTION_VIEW);
- 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));
- }
- launchIntent.setDataAndType(path, mimetype);
- launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- try {
- context.startActivity(launchIntent);
- } catch (ActivityNotFoundException ex) {
- Toast.makeText(context,
- R.string.download_no_application_title,
- Toast.LENGTH_LONG).show();
- }
- } else if (Intent.ACTION_DELETE.equals(action)) {
- if (deleteFile(cr, filename, mimetype)) {
- cr.delete(data, null, null);
+ Cursor cursor = null;
+ try {
+ cursor = cr.query(data,
+ new String[] { Downloads.Impl._ID, Downloads.Impl._DATA,
+ Downloads.Impl.COLUMN_MIME_TYPE, Downloads.COLUMN_STATUS },
+ null, null, null);
+ if (cursor.moveToFirst()) {
+ String filename = cursor.getString(1);
+ String mimetype = cursor.getString(2);
+ String action = intent.getAction();
+ if (Downloads.ACTION_NOTIFICATION_CLICKED.equals(action)) {
+ int status = cursor.getInt(3);
+ if (Downloads.isStatusCompleted(status)) {
+ Intent launchIntent = new Intent(Intent.ACTION_VIEW);
+ 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));
+ }
+ launchIntent.setDataAndType(path, mimetype);
+ launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ context.startActivity(launchIntent);
+ } catch (ActivityNotFoundException ex) {
+ Toast.makeText(context,
+ R.string.download_no_application_title,
+ Toast.LENGTH_LONG).show();
+ }
+ } else {
+ // Open the downloads page
+ Intent pageView = new Intent(context,
+ BrowserDownloadPage.class);
+ pageView.setData(data);
+ pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(pageView);
+ }
+ } else if (Intent.ACTION_DELETE.equals(action)) {
+ if (deleteFile(cr, filename, mimetype)) {
+ cr.delete(data, null, null);
+ }
}
}
+ } finally {
+ if (cursor != null) cursor.close();
}
- cursor.close();
}
/**