Reputation:
I get a push notification from FCM. When my application is minimized or screen is locked, I see a title of notification : Here is your notification and different icon.
How I can change this? This is my code and how I create and display a notification I don't have this:
private void createNotification( String messageBody) {
Intent intent = new Intent( this , NotificationActivity. class );
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultIntent = PendingIntent.getActivity( this , 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Wiadomosc z serwera")
.setContentText(messageBody)
.setAutoCancel( true )
.setSound(notificationSoundURI)
.setContentIntent(resultIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mNotificationBuilder.build());
}
Upvotes: 0
Views: 219
Reputation: 397
You'll have to use setLargeIcon(Bitmap bitmap)
method.
Bitmap largeIconBitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.launcher_logo);
NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
.setLargeIcon(largeIconBitmap)
.setSmallIcon(R.mipmap.ic_launcher)
Upvotes: 0
Reputation: 1672
Modified createNotification method .
1 . Add setLargeIcon() method to set large icon .
2 . Put your own title in setTitle() method .
private void createNotification( String messageBody) {
Intent intent = new Intent( this , NotificationActivity. class );
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultIntent = PendingIntent.getActivity( this , 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
.setSmallIcon(R.mipmap.ic_launcher) /*Icon to display in the Notification Bar */
.setLargeIcon(R.mipmap.largeicon) /*Icon to display when you scroll down notification tray */
.setContentTitle("Your own Title") /*Notification Title which will display when you scroll down Notification tray */
.setContentText(messageBody)
.setAutoCancel( true )
.setSound(notificationSoundURI)
.setContentIntent(resultIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mNotificationBuilder.build());
}
Upvotes: 1