NotificationCompat with API 26

Create the NotificationChannel only if API >= 26 public void initChannels(Context context) { if (Build.VERSION.SDK_INT < 26) { return; } NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel channel = new NotificationChannel(“default”, “Channel name”, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(“Channel description”); notificationManager.createNotificationChannel(channel); } And then just use: NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, “default”); So your notifications are working with both API … Read more

How to open fragment page, when pressed a notification in android

If you are using Navigation Component you can open a specific destination using NavDeepLinkBuilder: val pendingIntent = NavDeepLinkBuilder(context) .setComponentName(MainActivity::class.java) .setGraph(R.navigation.nav_graph) .setDestination(R.id.destination) .setArguments(bundle) .createPendingIntent() … notificationBuilder.setContentIntent(pendingIntent) … Please note that it’s important to use setComponentName only if your destination isn’t in the launcher activity.

How to create a notification with NotificationCompat.Builder?

The NotificationCompat.Builder is the most easy way to create Notifications on all Android versions. You can even use features that are available with Android 4.1. If your app runs on devices with Android >=4.1 the new features will be used, if run on Android <4.1 the notification will be an simple old notification. To create … Read more

Update text of notification, not entire notification

Be sure to use the same NotificationCompat.Builder builder each time for creating the Notification! Although the first time you have to set everything, the second time using the Builder you only have to set the value(s) you want to update. After that it’s calling notificationManager.notify(id, builder.build()) just like you did. If you use the same … Read more

Android Color Notification Icon

I found the answer to my question here: https://stackoverflow.com/a/44950197/4394594 I don’t know entirely what the problem was, but by putting the huge png that I was using for the icon into the this tool https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_skylight_notification and by placing the generated icons it gave into my mipmap folder, I was able to get the setColor(…) property … Read more

tech