Simple Notification:
private final String Channel_ID = "com.nirjhor3029.notification.nirjhor";
private final int Notification_id = 0031;
NotificationCompat.Builder builder ;
@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
builder = new NotificationCompat.Builder(this,Channel_ID);
builder.setAutoCancel(true);
}
public void simpleNotification(View view) {
createNotificationChannel();
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setTicker("This is Ticker !");
builder.setContentTitle("Notification Title");
builder.setContentText("This is notification body or text!");
builder.setSubText("this is subText");
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setWhen(System.currentTimeMillis());
Intent intent = new Intent(this,MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(Notification_id,builder.build());
}
private void createNotificationChannel()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
CharSequence name = "Personal Notification1";
String description = "Include all the personal notification1";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel notificationChannel = new NotificationChannel(Channel_ID,name,importance);
notificationChannel.setDescription(description);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.createNotificationChannel(notificationChannel);
}
}
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন