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
Related
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());
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);
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());
}
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());
I'm using this library https://github.com/commonsguy/cwac-updater to provide feature of auto update for an app.
I read the demoUpdater it uses a deprecated API for Notification, so I used the following code:
ConfirmationStrategy buildPreDownloadConfirmationStrategy(Context mContext) {
long[] vibrate = { 0, 100, 200, 300 };
NotificationManager mNotificationManager= (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Update Available")
.setContentText("Click to download the update!")
.setVibrate(vibrate)
.setAutoCancel(true)
.setLights(Color.BLUE, 500, 500);
mNotificationManager.notify(1, mBuilder.build());
return null;
//return(new NotificationConfirmationStrategy());
}
but can't get it working.
I got it working, If anyone finds trouble then use below code
ConfirmationStrategy buildPreDownloadConfirmationStrategy(Context mContext) {
long[] vibrate = { 0, 100, 200, 300 };
NotificationManager mNotificationManager= (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Update Available")
.setContentText("Click to download the update!")
.setVibrate(vibrate)
.setAutoCancel(true)
.setLights(Color.BLUE, 500, 500);
Notification notification = mBuilder.build();
mNotificationManager.notify(1, notification);
return(new NotificationConfirmationStrategy(notification));
}