Notification setStyle is not working in lollipop - android

I'm stuck in notificaion.
When I run below code under lollipop and over lollipop, it works fine.
However, if I run codes in lollipop, setstyle() method is not working.
I also tried with remoteviews, but it also not work.
I tried with BigPicture ,but it also doesn't work.
What did I miss?
Please help.
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(largeIcon)
.setContentTitle(title)
.setContentText(content)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setAutoCancel(true)
.setVibrate(new long[]{1000, 1000, 1000})
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
I tried with many devices and found that it happens in android version 5.0.2.

I don't find any problem except setContentText() remove it and give a try to the following :
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(largeIcon)
.setContentTitle(title)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setAutoCancel(true)
.setVibrate(new long[]{1000, 1000, 1000})
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

Related

Notification on Galaxy Watch (tizen) does not display icon

I have simple application that sends notifications, which I want to show on Samsung Watch (Active 2). The notification itself is shown on watch, but I cannot get Icon to be displayed. Here is example of notification from gmail and from my app. On gmail (left) you can see icon of the app, while on the right you cannot. What am I missing?
notification-shown
Relevant code I use is below:
int notificationId = 001;
Bitmap bIcon = BitmapFactory.decodeResource( getResources(),R.drawable.ic_stat_ic_notification);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setLargeIcon(bIcon)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationCompat.WearableExtender wearableExtender =
new NotificationCompat.WearableExtender().setContentAction(0);
notificationBuilder.extend(wearableExtender);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Home Notifier", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(notificationId /* ID of notification */, notificationBuilder.build());

Badge not appearing on application icon in a Launcher but notification came and is visible

My notification came and everything works perfectly, but my application icon does not have a badge.
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(prepareTitleMessage(remoteMessage.getNotification()))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setGroup(NOTIFICATION_CHANNEL)
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setVibrate(new long[]{1000, 1000})
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(remoteMessage.getNotification().getBody()));
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
channel.setShowBadge(true);
manager.createNotificationChannel(channel);
manager.notify(requestCode, notificationBuilder.build());

Android Studio Notification Lights

Why are the LED Lights not working with this Notification?
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setDefaults(0)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getData().get("username"))
.setContentText(remoteMessage.getNotification().getBody())
.setVibrate(new long[]{1500, 0, 1500, 0})
.setLights(Color.BLUE, 2000, 1000)
.setWhen(remoteMessage.getSentTime())
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody()))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
Can you help? I cant find the error.
I put the notificationBuilder.setDefaults(0) on top but it is still not working

Android notification sound doesn't work

var notificationBuilder = new Notification.Builder(context)
.SetSmallIcon(Resource.Drawable.Icon)
.SetLargeIcon(BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.Icon))
.SetContentTitle(title)
.SetContentText(message)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent)
.SetStyle(new Notification.BigTextStyle().BigText(message))
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
.SetVibrate(new long[] { 1000, 1000 })
.SetDefaults(NotificationDefaults.All);
var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
notificationManager.Notify(0, notificationBuilder.Build());
Where i was wrong? Why my notifications doesn't have any sound or vibration?
Remove .SetDefaults(NotificationDefaults.All), you are resetting the notification settings that you just built:
var notification = new Notification.Builder(Application.Context)
.SetSmallIcon(Resource.Mipmap.Icon)
.SetLargeIcon(BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Mipmap.Icon))
.SetContentTitle("Stack")
.SetContentText("OverFlow")
.SetAutoCancel(true)
//.SetContentIntent(pendingIntent)
.SetStyle(new Notification.BigTextStyle().BigText("OverFlow"))
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
.SetVibrate(new long[] { 1000, 1000 })
.Build();
var notificationManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);
notificationManager.Notify(1, notification);
Try passing uri to setSound in notificationBuilder like this
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationBuilder.setSound(uri);

Android Push Notification: Style doesn't work when application is closed or killed

NotificationCompat.InboxStyle notifInbox = new NotificationCompat.InboxStyle();
notifInbox.addLine("First Word");
notifInbox.addLine("Second Word");
notifInbox.addLine("Third Word");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notificon)
.setContentTitle(title)
.setSubText("FROM: SYSTEM")
.setContentInfo("X")
.setStyle(notifInbox)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
Why is it when my application is closed or killed, then I send a notification, the style doesn't work? Or how to prevent the notification to show when the application closed or killed? I'm using FCM. Any help is appreciated.
It's working for me you can try it.
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
// Do something for lollipop and above versions
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setPriority(Notification.PRIORITY_HIGH)
.setContentTitle(TextUtils.isEmpty(title) ? "XYZ" : title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg)
.setColor(getResources().getColor(R.color.colorPrimary));
mBuilder.setSound(Uri.parse("content://settings/system/notification_sound"));
mBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
} else {
// do something for phones running an SDK before lollipop
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(TextUtils.isEmpty(title) ? "xyz" : title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setSound(Uri.parse("content://settings/system/notification_sound"));
mBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

Categories

Resources