Skip to content

Instantly share code, notes, and snippets.

@francisnnumbi
Created July 20, 2017 18:31
Show Gist options
  • Save francisnnumbi/2b4806567316edcc510f4a679e23f5e8 to your computer and use it in GitHub Desktop.
Save francisnnumbi/2b4806567316edcc510f4a679e23f5e8 to your computer and use it in GitHub Desktop.
This is a snippet of a method that enables you to show a notification with minimum requirements. 3 arguments are required: - the id that is unique, if you use same id for different notifications the previous ones will be replaced by recent ones. - title of the notification. - message to display. But remember that a notification needs an icon for…
/**
* This is the simplest method that enables you to pop a notification with a minimum requirement
* Remember to add an icon as an icon or a drawable
*/
public void popNotification(int notifId, String title, String msg){
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notif = new Notification.Builder(getBaseContext())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(msg)
.setAutoCancel(true)
.build();
nm.notify(notifId, notif);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment