Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
[Fix #78] Add notification channel support (Android)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Brosy committed Aug 28, 2017
1 parent b05f60a commit 20f2881
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
Empty file modified config/fcm.php
100755 → 100644
Empty file.
Empty file modified phpunit.xml
100755 → 100644
Empty file.
9 changes: 9 additions & 0 deletions src/Message/PayloadNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class PayloadNotification implements Arrayable
*/
protected $body;

/**
* @internal
*
* @var null/string
*/
protected $channelId;

/**
* @internal
*
Expand Down Expand Up @@ -102,6 +109,7 @@ public function __construct(PayloadNotificationBuilder $builder)
{
$this->title = $builder->getTitle();
$this->body = $builder->getBody();
$this->channelId = $builder->getChannelId();
$this->icon = $builder->getIcon();
$this->sound = $builder->getSound();
$this->badge = $builder->getBadge();
Expand All @@ -124,6 +132,7 @@ public function toArray()
$notification = [
'title' => $this->title,
'body' => $this->body,
'android_channel_id' => $this->channelId,
'icon' => $this->icon,
'sound' => $this->sound,
'badge' => $this->badge,
Expand Down
31 changes: 31 additions & 0 deletions src/Message/PayloadNotificationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class PayloadNotificationBuilder
*/
protected $sound;

/**
* @internal
*
* @var null|string
*/
protected $channelId;

/**
* @internal
*
Expand Down Expand Up @@ -134,6 +141,20 @@ public function setBody($body)
return $this;
}

/**
* Set a channel ID for android API >= 26.
*
* @param string $channelId
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setChannelId($channelId)
{
$this->channelId = $channelId;

return $this;
}

/**
* Supported Android
* Indicates notification icon. example : Sets value to myicon for drawable resource myicon.
Expand Down Expand Up @@ -304,6 +325,16 @@ public function getBody()
return $this->body;
}

/**
* Get channel id for android api >= 26
*
* @return null|string
*/
public function getChannelId()
{
return $this->channelId;
}

/**
* Get Icon.
*
Expand Down
5 changes: 4 additions & 1 deletion tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function it_construct_a_valid_json_with_notification()
$targetFull = '{
"title":"test_title",
"body":"test_body",
"android_channel_id":"test_channel_id",
"badge":"test_badge",
"sound":"test_sound",
"tag":"test_tag",
Expand All @@ -112,7 +113,9 @@ public function it_construct_a_valid_json_with_notification()
$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetPartial, $json);

$notificationBuilder->setTag('test_tag')
$notificationBuilder
->setChannelId('test_channel_id')
->setTag('test_tag')
->setColor('test_color')
->setClickAction('test_click_action')
->setBodyLocationKey('test_body_key')
Expand Down

0 comments on commit 20f2881

Please sign in to comment.