Git Product home page Git Product logo

Comments (4)

brozot avatar brozot commented on July 24, 2024

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.

loreberti89 avatar loreberti89 commented on July 24, 2024

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.

brozot avatar brozot commented on July 24, 2024

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.

loreberti89 avatar loreberti89 commented on July 24, 2024

Yes! it Work!
thank you!

from laravel-fcm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.