How to update Notification with RemoteViews?

Here’s a detail example for you to update the notification using RemoteViews: private static final int NOTIF_ID = 1234; private NotificationCompat.Builder mBuilder; private NotificationManager mNotificationManager; private RemoteViews mRemoteViews; private Notification mNotification; … // call this method to setup notification for the first time private void setUpNotification(){ mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // we need to build … 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

Any way to link to the Android notification settings for my app?

The following will work in Android 5.0 (Lollipop) and above: Intent intent = new Intent(); intent.setAction(“android.settings.APP_NOTIFICATION_SETTINGS”); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //for Android 5-7 intent.putExtra(“app_package”, getPackageName()); intent.putExtra(“app_uid”, getApplicationInfo().uid); // for Android 8 and above intent.putExtra(“android.provider.extra.APP_PACKAGE”, getPackageName()); startActivity(intent); Notes: This is not officially supported in Android 5-7, but it works just fine. It IS officially supported as of Android 8. … Read more

Adding button action in custom notification

Start notification as: private void startNotification(){ String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis()); RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.mynotification); //the intent that is started when the notification is clicked (works) Intent notificationIntent = new Intent(this, FlashLight.class); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentView = notificationView; … Read more

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

Cancel notification on remove application from multitask panel

Killing Notifications when main app has been killed. Since your notification and your app are handled in different threads killing your app via MultitaskManager won’t kill your notification. As you already correctly investigated killing your app won’t even necesarrily result in an onExit() callback. So what is the solutions? You could start a service from … Read more