public void onClick(View view) { displayNotification(); } protected void displayNotification() { //---PendingIntent to launch activity if the user selects // this notification--- Intent i = new Intent(this, NotificationView.class); i.putExtra("notificationID", notificationID); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, 0); long[] vibrate = new long[] { 100, 250, 100, 500}; //Notification Channel - novo od Android O String NOTIFICATION_CHANNEL_ID = "my_channel_01"; CharSequence channelName = "hr.math.karga.MYNOTIF"; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setVibrationPattern(vibrate); //za sve verzije NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // za Notification Chanel nm.createNotificationChannel(notificationChannel); //ovako je i u starim verzijama, jedino dodano .setChannelId (za stare verzije to brisemo) Notification notif = new Notification.Builder(this) .setTicker("Reminder: meeting starts in 5 minutes") .setContentTitle("Meeting with customer at 3pm...") .setContentText("this is the second row") .setSmallIcon(R.mipmap.ic_launcher) .setWhen(System.currentTimeMillis()) .setShowWhen(true) .setContentIntent(pendingIntent) .setVibrate(vibrate) .setChannelId(NOTIFICATION_CHANNEL_ID) .build(); //najnovije, od API level 26.1.0., .setWhen ide po defautlu ovdje na currentTimeMillis /* final NotificationCompat.Builder notif = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID) .setDefaults(Notification.DEFAULT_ALL) .setSmallIcon(R.mipmap.ic_launcher) .setVibrate(vibrate) .setSound(null) .setChannelId(NOTIFICATION_CHANNEL_ID) .setContentTitle("Meeting with customer at 3pm...") .setContentText("this is the second row") .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setTicker("Reminder: meeting starts in 5 minutes") .setContentIntent(pendingIntent) .setAutoCancel(false); */ // za sve verzije nm.notify(notificationID, notif); }