I use this class to show notification whit my own UI (RemoteViews) , received from firebase console. This works fine when the app is foreground , but when the app is in background, notification displayed in default style of device.What should I do to show notification in my own UI even the app is foreground or background?
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "Mehdi";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
super.onMessageReceived(remoteMessage);
if (remoteMessage.getNotification() != null)
{
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.payam_notification_layout);
contentView.setTextViewText(R.id.payam,remoteMessage.getNotification().getBody());
String channelId = "Default";
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this,channelId)
.setSmallIcon(R.drawable.status_icon_delivered)
.setLargeIcon(BitmapFactory.decodeResource( getResources(), R.mipmap.icon))
.setSound(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.notification))
.setCustomBigContentView(contentView)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
manager.notify(0, mBuilder.build());
}
}
}
Note : thanks for the correct answer, I could send notification with my own UI by using this link , even app is in background or foreground : http://www.androiddeft.com/2017/11/18/push-notification-android-firebase-php/