I'm working on an android application, I need to show an account in the main icon of the application, in android oreo works the class Notification Badge, but in android 9 in a google pixel does not show it, and in Sony Xperia XZ2 with android Pie does not work either it does not show the unread notifications icon.
I have tried with third-party libraries like ShortcutBadger and the like, but they are not compatible with new android versions
NotificationChannel fyfChannel = new NotificationChannel(FYF_CHANNEL__ID, FYF_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
fyfChannel.enableLights(true);
fyfChannel.enableVibration(true);
fyfChannel.setLightColor(Color.GREEN);
fyfChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
fyfChannel.setShowBadge(true);
AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
fyfChannel.setSound( Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.audio1), audioAttributes);
getManager().createNotificationChannel(fyfChannel);
Please try this :
String NOTIF_CHANNEL_ID = "my_notification_channel";
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this, NOTIF_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentText(message)
.setContentTitle("RideWhiz")
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Configure the notification channel.
NotificationChannel notifChannel = new NotificationChannel(NOTIF_CHANNEL_ID, message, NotificationManager.IMPORTANCE_DEFAULT);
notifChannel.setDescription(message);
notifChannel.enableLights(true);
notifChannel.setLightColor(Color.GREEN);
notifChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notifChannel.enableVibration(true);
notificationManager.createNotificationChannel(notifChannel);
}
notificationManager.notify((int)System.currentTimeMillis(), notifBuilder.build());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.