Skip to content

Instantly share code, notes, and snippets.

@markormesher
Created March 15, 2016 15:34
Show Gist options
  • Save markormesher/142d03475ece42da1710 to your computer and use it in GitHub Desktop.
Save markormesher/142d03475ece42da1710 to your computer and use it in GitHub Desktop.
// increment the ID
++notificationId;
// create a notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(BasicNotificationActivity.this)
.setContentTitle("This is notification #" + notificationId)
.setContentText("This is the text!")
.setAutoCancel(true)
.setSmallIcon(R.drawable.kcl_tech_logo)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.kcl_tech_logo))
.setVibrate(new long[]{500, 500, 200, 500})
.setLights(0xff00ff00, 500, 200);
// create an action to complete when the notification is clicked
Intent intent = new Intent(BasicNotificationActivity.this, NotificationClickedActivity.class);
intent.putExtra("message", "You clicked notification #" + notificationId);
PendingIntent pendingIntent = PendingIntent.getActivity(BasicNotificationActivity.this, notificationId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// set the action on the notification
builder.setContentIntent(pendingIntent);
// get the notification manager
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// send the notification
manager.notify(notificationId, builder.build());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment