Each market currently requires targetsDkVersion at least 26, which is Android 8.0. This affects many functions, such as notifications.

When targetsdkVersion >= 26, you need to add a channel for the notification, for example

manager = (NotificationManager) BaseApp.getAppContext()
        .getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel("update"."update", NotificationManager.IMPORTANCE_DEFAULT);
    manager.createNotificationChannel(channel);
}
builder = new NotificationCompat.Builder(BaseApp.getAppContext(), "update");
Copy the code

Must first create a NotificationChannel, and call the NotificationManager createNotificationChannel enable the channel.

Then set the same channelID when you create the Buidler.

mute

So what if you want to mute notifications?

  • You can set it on a channel,setSound(null, null). Note If the channel is already installed and the channel already exists, the overwrite installation will not take effect and you need to uninstall and reinstall the channel.
  • You can also set the Builder,setOnlyAlertOnce(true). Note that this is not completely silent, but let the notification only ring once, such as when the download progress is displayed, so it doesn’t ring all the time.
manager = (NotificationManager) BaseApp.getAppContext()
        .getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel("update"."update", NotificationManager.IMPORTANCE_DEFAULT);
    channel.setSound(null.null);
    manager.createNotificationChannel(channel);
}
builder = new NotificationCompat.Builder(BaseApp.getAppContext(), "update"); . builder.setOnlyAlertOnce(true);
Copy the code

Pay attention to the public number: BennuCTech, get more dry goods!