Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1753)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java

Issue 2606753002: Post notification after fetching articles (Closed)
Patch Set: Add TODO. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/BUILD.gn » ('j') | chrome/browser/ntp_snippets/ntp_snippets_features.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
index fbe8a13a88505feb373317f6c8b2ed301515abcc..fb4056d042b5345374c7459d86ae96e70a890e1e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
@@ -4,13 +4,18 @@
package org.chromium.chrome.browser.ntp;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.Browser;
+import android.support.v4.app.NotificationCompat;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.R;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
@@ -21,6 +26,9 @@ import org.chromium.chrome.browser.document.ChromeLauncherActivity;
* Exposes helper functions to native C++ code.
*/
public class ContentSuggestionsNotificationHelper {
+ private static final String NOTIFICATION_TAG = "ContentSuggestionsNotification";
+ private static final int NOTIFICATION_ID = 0;
+
private ContentSuggestionsNotificationHelper() {} // Prevent instantiation
@CalledByNative
@@ -36,4 +44,34 @@ public class ContentSuggestionsNotificationHelper {
IntentHandler.addTrustedIntentExtras(intent, context);
context.startActivity(intent);
}
+
+ @CalledByNative
+ private static void showNotification(String url, String title, String text, Bitmap image) {
+ Context context = ContextUtils.getApplicationContext();
+ NotificationManager manager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ Intent intent = new Intent()
+ .setAction(Intent.ACTION_VIEW)
+ .setData(Uri.parse(url))
+ .setClass(context, ChromeLauncherActivity.class)
+ .putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true)
+ .putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
+ NotificationCompat.Builder builder =
+ new NotificationCompat.Builder(context)
+ .setAutoCancel(true)
+ .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
+ .setContentTitle(title)
+ .setContentText(text)
+ .setLargeIcon(image)
+ .setSmallIcon(R.drawable.ic_chrome);
+ manager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build());
+ }
+
+ @CalledByNative
+ private static void hideNotification() {
+ Context context = ContextUtils.getApplicationContext();
+ NotificationManager manager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ manager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID);
+ }
}
« no previous file with comments | « no previous file | chrome/browser/BUILD.gn » ('j') | chrome/browser/ntp_snippets/ntp_snippets_features.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698