Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, 20 October 2018

Nougat and oreo notification



String channelId = "default";
String title = context.getString(R.string.app_name);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 101, intent, PendingIntent.FLAG_UPDATE_CURRENT);

// Foreground Notification ContextNotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);

Notification notification = notificationBuilder
        .setContentTitle(title)
        .setSmallIcon(android.R.drawable.btn_star)
        .setContentText("Alarm Counter")
        .setAutoCancel(true)
        .setContentIntent(pendingIntent)
        .setWhen(System.currentTimeMillis())
        .build();

// Notification Channelif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(channelId, title, NotificationManager.IMPORTANCE_DEFAULT);
    channel.setDescription("Silent Notification");
    channel.setSound(null, null);
    channel.enableLights(false);
    channel.setLightColor(Color.BLUE);
    channel.enableVibration(false);
    notificationManager.createNotificationChannel(channel);

}
startForeground(1, notification);

No comments:

Post a Comment