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); |
+ } |
} |