Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background android notification #34

Open
develgooapps opened this issue Mar 8, 2019 · 3 comments
Open

Background android notification #34

develgooapps opened this issue Mar 8, 2019 · 3 comments

Comments

@develgooapps
Copy link

If I sent the notification to an individual devices as shown in the documentation, if the app is background and we click on it in the noitification section the app does not open.

I have tried everything, please help!

@redjanym
Copy link

redjanym commented Mar 8, 2019

How are sending the notification? Can you paste your code?

FCM documentation states that only Data Notifications are caught by the app when in background. Instead Message Notifications are only when app in in foreground.

@develgooapps
Copy link
Author

Like that:

        $client = new Client();
        $client->setApiKey($this->key);
        $client->injectGuzzleHttpClient(new ClientHttp());
        $message = new Message();
        $message->setPriority('high');
        $notif = new Notification($title, $messageText);
        $notif->setClickAction('MainApplication');
        $notif->setSound("default");
        $message->addRecipient(new Device($user->getFirebaseToken()));
        $message
            ->setNotification($notif)
            ->setData($data);
        $response = $client->send($message);

@redjanym
Copy link

The issue is in the fact that you send the notification as a Message Notification instead of Data Notification.

 $notif = new Notification($title, $messageText);

Here you are setting the title and body of the notification and this is handled automatically by the device to show the notifications. Instead if you need to make the notification show also when the app is in background you need to leave this 2 properties empty and set title and body in the Data property.

 $notif = new Notification();
.... // add all your settings of Notification then:
$message
            ->setNotification($notif)
            ->setData([
                'title' => 'this is a title',
                'body' => 'this is a body'
            ]);

This will require you to create a listener in the mobile app which will get the title and body and manually generate the notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants