Skip to content

Instantly share code, notes, and snippets.

@donrokzon
Created May 16, 2017 08:48
Show Gist options
  • Select an option

  • Save donrokzon/53321ad4800192fe80709859cc810906 to your computer and use it in GitHub Desktop.

Select an option

Save donrokzon/53321ad4800192fe80709859cc810906 to your computer and use it in GitHub Desktop.
NotificationManager manager;
private void createNotification() {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification)
.setContentTitle("My notification")
.setOngoing(true)
.setContentText("Hello World!");
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(contentIntent);
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, mBuilder.build());
}
void cancelNot(){
manager.cancel(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment