Created
December 12, 2019 09:50
-
-
Save sarkerrabi/b083e733d0a57f54270cb3027c689073 to your computer and use it in GitHub Desktop.
To Make a notification just call it from a method or anywhere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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