Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. int icon = R.drawable.ic_launcher;
  2. long when = System.currentTimeMillis();
  3. Notification notification = new Notification(icon, "Custom Notification", when);
  4.  
  5. NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  6.  
  7. RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
  8. contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
  9. contentView.setTextViewText(R.id.title, "Custom notification");
  10. contentView.setTextViewText(R.id.text, "This is a custom layout");
  11. notification.contentView = contentView;
  12.  
  13. Intent notificationIntent = new Intent(this, MainActivity.class);
  14. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
  15. notification.contentIntent = contentIntent;
  16.  
  17. notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
  18. notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
  19. notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
  20. notification.defaults |= Notification.DEFAULT_SOUND; // Sound
  21.  
  22. mNotificationManager.notify(1, notification);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement