Notification icon display as Square in Nougat - android

Hello I have implemented Push notifications in my application.
It's working fine and displaying notification icon properly for the devices below nougat version.
But, It displaying notification icon as Square with color white.
Below is my code :
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.app_icon)
.setColor(ContextCompat.getColor(getApplicationContext(),R.color.white))
.setContentTitle(strTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(++NOTIFICATION_ID /* ID of notification */, notificationBuilder.build());

First of all , this is not an error. It is a change in the design with Android Nougat
For Android Nougat, you should provide rounded icon for notification.
Check out this link and this for more details.

Related

Android Notification small icon not showing white square instead in 7.1.1 above

In push notification, the small icon is not showing in 7.1.1 above OS.White square like coming
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
Notification notification = mBuilder.
setSmallIcon(R.drawable.notification_icon).
setTicker("testing").setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(contentIntent)
.setSound(defaultSoundUri)
.setContentText(message)
.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_ID, notification);
I'm using transparent background but I'm not able to show correctly please help me.Even I follow the android icon design guidelines.

BigPictureStyle Notification not showing properly in Xiaomi MIUI-8

I wanted to display a bigPictureStyle Notification in MiUi(don't want to use custom view) using the following code--
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(msg)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.b))
.setBigContentTitle(title));
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(10, mBuilder.build());
It works perfectly on raw android but in Xiaomi MIUI 8 (Android Lollipop based) it shows a shadow at the bottom of expanded notification view as in the picture--
How to remove this bottom shadow?
The only solution for now is using a custom view with similar looking big content view.

Some Devices are not displaying Message body, only title is visible

This is how i am displaying Push Notification to user.
Notification notification = new Notification.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(intent)
.setContentTitle("Title")
.setStyle(new Notification.BigTextStyle()
.bigText(msg))
.setSound(soundUri)
.build();
notificationManager.notify(0, notification);
This is working fine on Samsung s5, Samsung s7. But on samsung Note3 , it only displays title, and does not display message body. This may be occurring in some other devices as well.
Kindly guide me that what can be the reason of this.
Adding .setContentText(msg) to your call chain should solve the problem.
Android documentation for NotificationCompat states that "If the platform does not provide rich notification styles, [setStyle(Style style)] has no effect". I'm going to take a leap of faith and say that this is the cause of the problem.
Try this code
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(intent)
.setContentTitle("Title")
.setStyle(new Notification.BigTextStyle()
.bigText(msg))
.setSound(soundUri)
.setContentText(detail);
NotificationManager mNotifyMgr =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());

Android notification white circle when app is not running [duplicate]

This question already has answers here:
Notification Icon with the new Firebase Cloud Messaging system
(10 answers)
Closed 6 years ago.
I'm using Firebase Notification for my app's push notifications.
All working well but notification icon shows white circle when app is not running.
I'm targeting SDK version 23, also I'm using Roman Nurik's notification icon generator to generate white-on-transparent icons.
Notification icon is showing correctly when app is on foreground and running. img
But icon gets replaced with generic white circle when app is in background or killed. img
Here's my notification builder method:
private void sendNotification(String messageTitle, String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notification_icon)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_DEFAULT)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification.build());
}
I've already found an answer on similar issue: Notification Icon with the new Firebase Cloud Messaging system
Unfortunately this is a limitation of Firebase Notifications in SDK
9.0.0. When the app is in the background the launcher icon is use from the manifest (with the requisite Android tinting) for messages sent
from the console.
If the app is in the foreground (or a data message is sent) you should
be able to use your own logic to customise, and you should be able to
customise the icon if sending the message from the HTTP/XMPP APIs.
Right now with messages sent from the console you'll get this
behavior.
It seems to be that the best way to avoid this Firebase Notifications bug is to change your targetSdkVersion in build.gradle to 19. The notification icon will be then colored. Firebase after a while will fix this issue.
Hope it will help
try this code:
Intent intent = new Intent(this, TabActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle("IDS DMS Support")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
I think that you need to add a silhouette icon to the app and use it if the device is running Android Lollipop.
Use below code to get small icon for notification.
protected int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
You can see full solution Here.
I did same thing and works fine.

Android: Adding notification to status bar

I have created a notification with NotificationCompat.Builder but i don't know how to show it in status bar. I tried using
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mId, mBuilder.build());
but it doesn't work on 2.2 so i need another way...
this is my notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification)
.setContentTitle("Message")
.setContentText("Notification");
but it doesn't work on 2.2
Yes it does.
This sample application shows an IntentService downloading a file and displaying a Notification using NotificationCompat.Builder. It uses code pretty much like yours for actually raising the Notification:
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, b.build());
This code works fine on Android 2.2, as I just tried it (again) on an emulator, and the Notification displays as expected.

Categories

Resources