-1

I have two problem with my app:

1. I don't know how to retrieve the color of the small icon of notification when a notification arrives?
2. Can I edit app name that displayed at top of the notification by programmatically?
I'm using android Nougat .

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
December
  • 11
  • 4

2 Answers2

1

You can use the below code to set smallIcon :(Use Small icon same color as Title Color)

Change color by this site

.setSmallIcon(R.drawable.ic_launcher_icon)

enter image description here

Reference Code :

 private void sendNotification(String messageBody,String message2, Bitmap image, String TrueOrFalse) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("AnotherActivity", TrueOrFalse);
    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)
           // .setLargeIcon(image)/*Notification icon image*/
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher_icon))
            .setSmallIcon(R.drawable.ic_launcher_icon)
            .setContentTitle(messageBody)
            .setContentText(message2)
            .setColor(getResources().getColor(R.color.colorAccent))
            .setStyle(new NotificationCompat.BigPictureStyle()
            .bigPicture(image))/*Notification with Image*/
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
  • Tks for answer. But I have to retrieve notification by onNotificationPosted(StatusBarNotification sbn) method. And I want get the small icon color of the notification that I just retrieved. How I do it? – December Mar 15 '18 at 14:11
0

This API seems to allow custom title and icon: https://developer.android.com/reference/android/app/Notification.Builder.html

antrunner
  • 87
  • 1
  • 6
  • Tks for your answer. But I want custom the app name that displayed at top of the notification. Do you know? – December Mar 15 '18 at 13:49
  • Only for the notification or for the entire app? – antrunner Mar 15 '18 at 13:59
  • Only for the notification. Because I need it to display different app name every time my app post notification – December Mar 15 '18 at 14:16
  • As far as I know, if the notification comes from a push server the operating system will receive the notification first and based on the app ID grab the current app title without the app knowing about the notification. Therefore, in this use case a custom title for notifications seems to be not possible. If the notification come from the app itsself, the app can set the app title before sending it to the system notification center and display the custom title everytime it sends a new notfiication. See: https://stackoverflow.com/questions/3975550/android-how-to-change-the-application-title – antrunner Mar 15 '18 at 14:37