I have implemented a Firebase notification in my Android app. When my application is running, a notification is displayed with my custom layout, but when the application is not running, a notification is displayed with the default layout. How to change the notification layout to my layout when the application is not running. In addition, I keep the general settings so that the user can switch notifications. But when the application does not start, a notification is displayed anyway. How can this be achieved?
@Override public void onMessageReceived(RemoteMessage remoteMessage) { if(SettingsFragment.getReceiceNotification()){ //if user wants to receive notification NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.push_notification_layout); remoteViews.setImageViewResource(R.id.push_notif_icon,R.mipmap.ic_bird_black); Intent intent = new Intent(this,MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContent(remoteViews); notificationBuilder.setContentTitle("Radyo Türkkuşu"); notificationBuilder.setContentText(remoteMessage.getNotification().getBody()); notificationBuilder.setAutoCancel(true); notificationBuilder.setSmallIcon(R.mipmap.ic_launcher); notificationBuilder.setContentIntent(pendingIntent); remoteViews.setTextViewText(R.id.push_title, "Radyo Türkkuşu"); remoteViews.setTextViewText(R.id.push_context, remoteMessage.getNotification().getBody()); //notificationBuilder.setLights (ContextCompat.getColor(MainActivity.context, R.color.pushColor), 5000, 5000); notificationManager.notify(0,notificationBuilder.build()); } }
android firebase firebase-cloud-messaging firebase-notifications
orkun
source share