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

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

Issue 2606753002: Post notification after fetching articles (Closed)
Patch Set: override Created 4 years 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
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..412887fafdd648e7a4056fd9f74f805defb9d6b9 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 TAG = "ContentSuggestionsNotification";
dgn 2016/12/28 11:00:26 nit: name it differently (NOTIFICATION_TAG maybe?)
sfiera 2017/01/05 13:35:01 Done.
+ private static final int 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(TAG, ID, builder.build());
+ }
+
+ @CalledByNative
+ private static void hideNotification() {
+ Context context = ContextUtils.getApplicationContext();
+ NotificationManager manager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ manager.cancel(TAG, ID);
+ }
}
« no previous file with comments | « no previous file | chrome/browser/BUILD.gn » ('j') | chrome/browser/android/ntp/content_suggestions_notifier_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698