Skip to content

Instantly share code, notes, and snippets.

@sarkerrabi
Created December 12, 2019 09:50
Show Gist options
  • Save sarkerrabi/b083e733d0a57f54270cb3027c689073 to your computer and use it in GitHub Desktop.
Save sarkerrabi/b083e733d0a57f54270cb3027c689073 to your computer and use it in GitHub Desktop.
To Make a notification just call it from a method or anywhere
//for greater than android O
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(CHANNEL_DESC);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
// to make notification details
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this,CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notifications)
.setContentTitle("Title")
.setContentText("Description")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(MainActivity.this);
//to notify the notification
managerCompat.notify(1,builder.build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment