Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. private static void generateNotification(Context context, String message) {
  2. int icon = R.drawable.ic_launcher;
  3. long when = System.currentTimeMillis();
  4. NotificationManager notificationManager = (NotificationManager)
  5. context.getSystemService(Context.NOTIFICATION_SERVICE);
  6. Notification notification = new Notification(icon, message, when);
  7.  
  8. String title = context.getString(R.string.app_name);
  9.  
  10. Intent notificationIntent = new Intent(context, MainActivity.class);
  11. // set intent so it does not start a new activity
  12. notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
  13. Intent.FLAG_ACTIVITY_SINGLE_TOP);
  14. PendingIntent intent =
  15. PendingIntent.getActivity(context, 0, notificationIntent, 0);
  16. notification.setLatestEventInfo(context, title, message, intent);
  17. notification.flags |= Notification.FLAG_AUTO_CANCEL;
  18. notification.defaults |= Notification.DEFAULT_SOUND;
  19. notification.defaults |= Notification.DEFAULT_VIBRATE;
  20. notificationManager.notify(0, notification);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement