make notifications appear during downloading AND after completion
bug:3132773
Change-Id: I012859fa86055f322069d5120b110c4c8887fb61
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index 5654599..570e494 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -26,7 +26,6 @@
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
-import android.provider.BaseColumns;
import android.provider.Downloads;
import android.util.Pair;
@@ -337,13 +336,34 @@
private List<Pair<String, String>> mRequestHeaders = new ArrayList<Pair<String, String>>();
private CharSequence mTitle;
private CharSequence mDescription;
- private boolean mShowNotification = true;
private String mMimeType;
private boolean mRoamingAllowed = true;
private int mAllowedNetworkTypes = ~0; // default to all network types allowed
private boolean mIsVisibleInDownloadsUi = true;
/**
+ * This download is visible but only shows in the notifications
+ * while it's in progress.
+ */
+ public static final int VISIBILITY_VISIBLE = 0;
+
+ /**
+ * This download is visible and shows in the notifications while
+ * in progress and after completion.
+ */
+ public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1;
+
+ /**
+ * This download doesn't show in the UI or in the notifications.
+ */
+ public static final int VISIBILITY_HIDDEN = 2;
+
+ /** can take any of the following values: {@link #VISIBILITY_HIDDEN}
+ * {@link #VISIBILITY_VISIBLE_NOTIFY_COMPLETED}, {@link #VISIBILITY_VISIBLE}
+ */
+ private int mNotificationVisibility = VISIBILITY_VISIBLE;
+
+ /**
* @param uri the HTTP URI to download.
*/
public Request(Uri uri) {
@@ -475,9 +495,33 @@
*
* @param show whether the download manager should show a notification for this download.
* @return this object
+ * @deprecated use {@link #setNotificationVisibility(int)}
*/
+ @Deprecated
public Request setShowRunningNotification(boolean show) {
- mShowNotification = show;
+ return (show) ? setNotificationVisibility(VISIBILITY_VISIBLE) :
+ setNotificationVisibility(VISIBILITY_HIDDEN);
+ }
+
+ /**
+ * Control whether a system notification is posted by the download manager while this
+ * download is running or when it is completed.
+ * If enabled, the download manager posts notifications about downloads
+ * through the system {@link android.app.NotificationManager}.
+ * By default, a notification is shown only when the download is in progress.
+ *<p>
+ * It can take the following values: {@link #VISIBILITY_HIDDEN},
+ * {@link #VISIBILITY_VISIBLE},
+ * {@link #VISIBILITY_VISIBLE_NOTIFY_COMPLETED}.
+ *<p>
+ * If set to {@link #VISIBILITY_HIDDEN}, this requires the permission
+ * android.permission.DOWNLOAD_WITHOUT_NOTIFICATION.
+ *
+ * @param visibility the visibility setting value
+ * @return this object
+ */
+ public Request setNotificationVisibility(int visibility) {
+ mNotificationVisibility = visibility;
return this;
}
@@ -540,10 +584,7 @@
putIfNonNull(values, Downloads.Impl.COLUMN_DESCRIPTION, mDescription);
putIfNonNull(values, Downloads.Impl.COLUMN_MIME_TYPE, mMimeType);
- values.put(Downloads.Impl.COLUMN_VISIBILITY,
- mShowNotification ? Downloads.Impl.VISIBILITY_VISIBLE
- : Downloads.Impl.VISIBILITY_HIDDEN);
-
+ values.put(Downloads.Impl.COLUMN_VISIBILITY, mNotificationVisibility);
values.put(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, mAllowedNetworkTypes);
values.put(Downloads.Impl.COLUMN_ALLOW_ROAMING, mRoamingAllowed);
values.put(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI, mIsVisibleInDownloadsUi);
diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java
index c9e3b69..7054888 100644
--- a/core/java/android/provider/Downloads.java
+++ b/core/java/android/provider/Downloads.java
@@ -16,6 +16,7 @@
package android.provider;
+import android.app.DownloadManager;
import android.net.Uri;
/**
@@ -621,18 +622,19 @@
* This download is visible but only shows in the notifications
* while it's in progress.
*/
- public static final int VISIBILITY_VISIBLE = 0;
+ public static final int VISIBILITY_VISIBLE = DownloadManager.Request.VISIBILITY_VISIBLE;
/**
* This download is visible and shows in the notifications while
* in progress and after completion.
*/
- public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1;
+ public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED =
+ DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED;
/**
* This download doesn't show in the UI or in the notifications.
*/
- public static final int VISIBILITY_HIDDEN = 2;
+ public static final int VISIBILITY_HIDDEN = DownloadManager.Request.VISIBILITY_HIDDEN;
/**
* Constants related to HTTP request headers associated with each download.