This is my Notification which i am receive notification from firebase.
this below code i have used to receive notification from firebase:
public class FirebaseMessageReceiver
extends FirebaseMessagingService {
Bitmap bitmap;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification().getImageUrl() != null) {
String imageUri = remoteMessage.getNotification().getImageUrl().toString();
bitmap = getBitmapfromUrl(imageUri);
sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), bitmap);
} else {
sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), null);
}
}
private void sendNotification(String messageTitle, String messageBody, Bitmap image) {
NotificationManager mNotificationManager;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, "notify_001");
Intent ii = new Intent(this, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, ii, PendingIntent.FLAG_MUTABLE);
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText("");
bigText.setBigContentTitle(messageTitle);
mBuilder.setContentIntent(pendingIntent);
mBuilder.setAutoCancel(true);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(R.drawable.icon_transperent);
mBuilder.setColor(getResources().getColor(R.color.full_transperent));
} else {
mBuilder.setSmallIcon(R.mipmap.ic_launcher_round);
}
if (image != null) {
mBuilder.setLargeIcon(image);
}
mBuilder.setContentText(messageBody);
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setStyle(bigText);
mNotificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "Your_channel_id";
NotificationChannel channel = new NotificationChannel(
channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(channelId);
}
mNotificationManager.notify(0, mBuilder.build());
}
/*
*To get a Bitmap image from the URL received
* */
public Bitmap getBitmapfromUrl(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);
return bitmap;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
}
I don't know what i am doing mistake but i am getting notification from Firebase but i am unable to see icon its showing rounded black icon please help me how we can show icon in notification section when i receive notification .