【发布时间】:2021-01-17 11:50:21
【问题描述】:
我有一个 Laravel 应用程序使用名为 laravel-fcm-notification 的包通过 firebase 云消息发送推送通知。
发送消息时,Laravel 应用程序一切正常,我收到了这样的回复
{
"multicast_id" => 524702081778807088
"success" => 1
"failure" => 0
"canonical_ids" => 0
}
封装代码
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;
}
安卓主祭
<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函数
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)
}
当我在前台时通知正在发送而不是在后台发送? 请问有什么帮助吗?
【问题讨论】:
标签: php laravel firebase google-api-client