I am using the below snippet to generate notifications in my android app.
private void sendNotification(String contentText, String message) {
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.putExtra("clear","clear");
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent piResult = PendingIntent.getActivity(this, 0, resultIntent,0);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
.setContentTitle("title")
.setContentText(message)
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources()
,R.drawable.notification))
.setContentIntent(piResult);
NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
int i;
for(i=0; i<messageList.size();i++){
notification.addLine(messageList.get(i));
}
notification.setBigContentTitle("title");
notification.setSummaryText(contentText);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID,notification.build());
}
It works in android 5 and 6 but for android nougat it is not working
Following the docs from the Android API:
Status bar icons are composed simply of white pixels on a transparent backdrop, with alpha blending used for smooth edges and internal texture where appropriate.
Your whole image but the transparent parts is going to be converted to white (being originally white or having colors).
One solution is to create a silhouette icon with color, by this way you can use the same image in all Android APIs. One example could be this icon:
In lower versions of Android you would see the black face, in the last versions you will see the same face but with white color. That's because of the transparent parts (it seems SO removes the transparency, you can get the original from here) of the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With