Skip to content

Commit 3525bff

Browse files
authored
added Android specifics + some formatting
1 parent d9bb3b4 commit 3525bff

File tree

1 file changed

+53
-27
lines changed

1 file changed

+53
-27
lines changed

Documentation/how-to-firebase-cloud-message.md

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,22 @@ $config = AndroidConfig::fromArray([
7777
'priority' => 'normal',
7878
'notification' => [
7979
'title' => '$GOOG up 1.43% on the day',
80+
'tag' => '$GOOG',
8081
'body' => '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
81-
'icon' => 'stock_ticker_update',
82-
'color' => '#f45342',
82+
'icon' => 'ic_stock_ticker',
83+
'color' => '#f45342'
8384
],
8485
]);
85-
8686
```
8787

88+
*Notification keys and value options*:
89+
`tag`: Identifier used to replace existing notifications in the notification drawer. If not specified, each request creates a new notification. If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
90+
91+
`color`: The notification's icon color, expressed in #rrggbb format.
92+
93+
`icon`: Unless specified, let the Android app deal with this. Kind of similar to sound, but with notification icons instead.
94+
95+
8896
PHP: iOS Specifc message
8997
```php
9098
$config = ApnsConfig::fromArray([
@@ -128,28 +136,28 @@ We always register userId as a topic `user_[ID]`eg `user_1`
128136

129137
Topics can be used very smart, and should avoid every situation of having to store push settings in the DB.
130138

131-
Example 1)
139+
## Example 1)
132140

133141
Feature: Push on breaking news which is optional for users (is a setting)
134142

135-
The app will register to a tag "breakingNews" if the push setting is on.
143+
The app will register to a tag `breakingNews` if the push setting is on.
136144
It's important to code this as a way where local storage is master
137145

138-
The backend will now just push to the tag "breakingNews"
146+
The backend will now just push to the tag `breakingNews`
139147

140-
Example 2)
148+
## Example 2)
141149

142150
Feature: Recieving push notifications about athlete with id: 12345, after favoriting him/her
143151

144-
The app will register to tag "athelete_12345"
152+
The app will register to tag `athelete_12345`
145153

146-
The backend will now just push to the tag "athlete\_[ID]" instead of looping users which have favorited it (maybe the state is even local)
154+
The backend will now just push to the tag `athlete\_[ID]` instead of looping users which have favorited it (maybe the state is even local)
147155

148-
Example 3)
156+
## Example 3)
149157

150158
The app have options to only receive news push notification during race or always
151159

152-
The app will register to tag "newsAlways" or "newsDuringRace" or both
160+
The app will register to tag `newsAlways` or `newsDuringRace` or both
153161

154162
Backend will push to those tags, but will figure out if the the current time is durring race and add that tag also.
155163

@@ -179,10 +187,7 @@ $message = ConditionalMessage::create($condition)
179187

180188
There is 3 options for sound
181189

182-
1) Standard device sound
183-
184-
Don't add anything
185-
Or for iOS add "default"
190+
### Standard device sound
186191

187192
PHP iOS Standard sound
188193
```php
@@ -195,10 +200,23 @@ PHP iOS Standard sound
195200
],
196201
]));
197202
```
203+
204+
PHP Android Standard sound
205+
```php
206+
$config = AndroidConfig::fromArray([
207+
'ttl' => '3600s',
208+
'priority' => 'normal',
209+
'notification' => [
210+
'title' => '$GOOG up 1.43% on the day',
211+
'body' => '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
212+
'sound' => 'default'
213+
],
214+
]);
215+
```
198216

199-
2) No sound
217+
### No sound
200218

201-
Android: Yet to figure out how this works in FCM, Please do PR
219+
Android: The documentation is pretty lackluster on this. For Android 8.0+ notification channel's will probably override this anyway.
202220
iOS: empty string. ""
203221

204222
PHP iOS No sound
@@ -213,19 +231,19 @@ PHP iOS No sound
213231
]));
214232
```
215233

216-
3) Custom sound
234+
### Custom sound
217235

218236
Here we have to set sound for ios & android specificly
219237

220-
The normal approach in Android is to link to the file name in /res/raw/
238+
`sound`: The sound to play when the device receives the notification. Supports "default" or the filename of a sound resource bundled in the app i.e. `stocksound.mp3`. Android: Sound files must reside in /res/raw/.
221239

222240
PHP Android example
223241

224242
```php
225243
->withAndroidConfig(AndroidConfig::fromArray([
226244
'notification' => [
227245
'title' => $message,
228-
'sound' => $androidSound ? ('res/raw/arrivedsound.mp3') : null,
246+
'sound' => $androidSound ? ('arrivedsound.mp3') : null,
229247
],
230248
]))
231249
```
@@ -247,7 +265,13 @@ PHP Android example
247265

248266
This is starting to be a very important matter, notification without high prio. Can easily take minutes to be send
249267

250-
PHP: Android high priority
268+
*PHP: Android high priority*
269+
270+
`priority`: Message priority. Can take "normal" and "high" values.
271+
272+
*Normal priority messages* are delivered immediately when the app is in the foreground. When the device is in Doze or the app is in app standby, delivery may be delayed to conserve battery. For less time-sensitive messages, such as notifications of new email, keeping your UI in sync, or syncing app data in the background, choose normal delivery priority.
273+
274+
FCM attempts to deliver *high priority messages* immediately, allowing the FCM service to wake a sleeping device when necessary and to run some limited processing (including very limited network access). High priority messages generally should result in user interaction with your app. If FCM detects a pattern in which they don't, your messages may be de-prioritized.
251275

252276
```php
253277
->withAndroidConfig(AndroidConfig::fromArray([
@@ -258,7 +282,7 @@ PHP: Android high priority
258282
]))
259283
```
260284

261-
PHP: iOS high priority
285+
*PHP: iOS high priority*
262286

263287
```php
264288
->withApnsConfig(ApnsConfig::fromArray([
@@ -281,7 +305,7 @@ No priority 10 is highest, but does not work together with content-available
281305
Sometimes we use push to notifity the phone about a update, but we do not want it to show in the notification center.
282306
eg booking was updated, with updates in payload or please pull newest booking
283307

284-
PHP iOS example
308+
### PHP iOS example
285309
```php
286310
$apns = [
287311
'payload' => [
@@ -303,16 +327,18 @@ PHP iOS example
303327

304328
->withApnsConfig($apns);
305329
```
330+
The reason of this code, is that "alert" & "sound" is not allowed when sending silent pushes. It should not even be in object, else it will be ignored as silent
331+
Same goes for priorty, 5 is highest for silent
306332

307-
PHP Android example, there is no real featuer for this. But android can read payload and decide not to build notification
333+
334+
### PHP Android example
335+
To send silent push notifications send a payload with only `data` object set. The Android app will then receive data payload in `onMessageReceived`.
308336
```php
309337
$message = $message->withData([
310-
'silent' => 'true',
338+
'someKey' => 'someValue',
311339
]);
312340
```
313341

314-
The reason of this code, is that "alert" & "sound" is not allowed when sending silent pushes. It should not even be in object, else it will be ignored as silent
315-
Same goes for priorty, 5 is highest for silent
316342

317343
## Badge count
318344
This is originally an iOS feature

0 commit comments

Comments
 (0)