Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. private static void generateNotification(Context context, NewsEntity news) {
  2. int icon = R.drawable.iconapp;
  3. long when = System.currentTimeMillis();
  4. NotificationManager notificationManager = (NotificationManager)
  5. context.getSystemService(Context.NOTIFICATION_SERVICE);
  6. String message="New News arrived!";
  7. Notification notification = new Notification(icon,message , when);
  8. String title = context.getString(R.string.app_name);
  9. Intent notificationIntent = new Intent(context, NewsDetailsActivity.class);
  10. // set intent so it does not start a new activity
  11. /*notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
  12. Intent.FLAG_ACTIVITY_SINGLE_TOP);*/
  13.  
  14. notificationIntent.putExtra("NewsTitle", news.getNewsTitle());
  15.  
  16.  
  17. notificationIntent.putExtra("NewsDateAndTime", news.getNewsDate());
  18. Log.e("ImageUrl", CommonUtilities.IMAGE_URL+news.getThumbnailURL());
  19.  
  20. notificationIntent.putExtra("NewsImage", CommonUtilities.IMAGE_URL+news.getThumbnailURL());
  21. notificationIntent.putExtra("NewsDescription", news.getNewsDescription());
  22.  
  23. Log.e("generateNotification NewsTitle: ,NewsDateAndTime ,NewsImage, NewsDescription: ", news.getNewsTitle()+","+news.getNewsDate()+","
  24. +CommonUtilities.IMAGE_URL+news.getThumbnailURL()+","+news.getNewsDescription());
  25. PendingIntent intent =
  26. PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  27. notification.setLatestEventInfo(context, title, message, intent);
  28. notification.flags |= Notification.FLAG_AUTO_CANCEL;
  29.  
  30. notificationManager.notify(0, notification);
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement