I have a Laravel application send push notification through firebase cloud messaging using a package called laravel-fcm-notification.
everything is working fine from the Laravel app when a message is sent I got a response like this
{
"multicast_id" => 524702081778807088
"success" => 1
"failure" => 0
"canonical_ids" => 0
}
package code
public function toFcm($notifiable)
{
$message = new FcmMessage();
$message->setHeaders([
'project_id' => "904447526427", // FCM sender_id 904447526427
])->content([
'title' => 'Invoice Approved',
'body' => 'test message from laravel package',
])->data([
'title' => "Salesman {$notifiable->name} requesting for discount",
'image' => 'placeholder.jpg ',
'message' => 'You got a new Message',
])->priority(FcmMessage::PRIORITY_HIGH); // Optional - Default is 'normal'.
return $message;
}
android mainfest
<service
android:name=".utils.services.MessagingController"
android:permission="signature"
android:stopWithTask="true"
android:enabled="true"
android:exported="true"
tools:ignore="Instantiatable">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
android function that received the notification
override fun onMessageReceived(remoteMessage: RemoteMessage) {
DLog("")
val data = remoteMessage.data
remoteMessage.notification?.let {
data.set(NOTI_TITLE , it.title)
data.set(NOTI_MESSAGE , it.body)
//Add more data if necessary
}
pushNotification.show(applicationContext, data)
}
the notification is comming when my in forground is not coming when its background? any help please?