Comments (4)
Hi,
For Firebase message notification does not support special notifications, use a data message because it call every time onMessageReceived.
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
maybe this thread can be help you : http://stackoverflow.com/questions/38504078/firebase-expandable-notification-show-image-when-app-is-in-background.
I hope that will help you . Please give me a feedback if that solve or not your issue.
Best regards
Nicolas
from laravel-fcm.
Hello, thankyou for your reply!
But my problem persist.
public function alert($text = null, $token, $action=null)
{
$optionBuiler = new OptionsBuilder();
$optionBuiler->setTimeToLive(60*20);
$notificationBuilder = new PayloadNotificationBuilder('NOTIFY');
$notificationBuilder->setBody($text)
->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$option = $optionBuiler->build();
FCM::sendTo($token, $option, $notification, $data);
}
I have this function, and when the app is open pass on onMessageReceived corretly, but when I close my app the onMessageReceived is not executed.
am I doing something wrong?
from laravel-fcm.
Hello, Try to remove the notification payload of your message like bellow:
public function alert($text = null, $token, $action=null)
{
$optionBuiler = new OptionsBuilder();
$optionBuiler->setTimeToLive(60*20);
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$data = $dataBuilder->build();
$option = $optionBuiler->build();
FCM::sendTo($token, $option, null, $data);
}
because when notification is present on the payload, android will handle the message and show it without passing in onMessageReceived when app is in background.
From FCM documentation :
Messages with both notification and data payloads
App behavior when receiving messages that include both notification and data payloads depends on whether the app is in the background or the foreground—essentially, whether or not it is active at the time of receipt.
When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
When in the foreground, your app receives a message object with both payloads available.
Here is a JSON-formatted message containing both the notification key and the data key:
{
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
Please could you test it and give me a feedback ?
from laravel-fcm.
Yes! it Work!
thank you!
from laravel-fcm.
Related Issues (20)
- Notification sound not working HOT 3
- Support guzzle 7.0
- send notification issue
- Change the connection on the fly
- SnederId Mismatch
- Lumen - Unable to resolve NULL driver for [LaravelFCM\FCMManager]. HOT 1
- onMessage payload not working HOT 1
- Laravel 8 HOT 6
- How to add badge on push notification using brozot/Laravel-FCM
- How to test FCM::sendTo with Feature test HOT 4
- Laravel 8 supported or not?(php 8) HOT 6
- How to send FCMGroup?
- Find exact error code or error message in responce
- How to add small icon on the right side of the notification.
- Not working on iOS devices HOT 2
- Your requirements could not be resolved to an installable set of packages. HOT 4
- Not compatible with guzzle ~7.0 HOT 1
- Not support in Laravel 9 HOT 1
- Not Support In Laravel 10 HOT 1
- Is this package abandoned?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-fcm.