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

Custom notification icon for android + documentation #2487

Closed
charlesverge opened this issue Jul 11, 2018 · 4 comments
Closed

Custom notification icon for android + documentation #2487

charlesverge opened this issue Jul 11, 2018 · 4 comments

Comments

@charlesverge
Copy link

Expected Behaviour

Use custom notification icon when application in background.

Actual Behaviour

Uses default icon which is a gray square on Android 7 due to not using custom icon for notifications

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Create app with platform android 7.1.0 phonegap 8.0.0

PushNotification.init({
android: {
"icon": "notification_icon",
},
ios: {
alert: "true",
badge: "true",
sound: "false"
},
windows: {}
});

Send notification to app over firebase

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 7.1.1

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Motorola 6

Cordova CLI version and cordova platform version

cordova --version                                    # e.g. 6.0.0
cordova platform version android                     # e.g. 4.1.1

Plugin version

cordova plugin version | grep phonegap-plugin-push   # e.g. 1.5.3

Sample Push Data Payload

[
'token' => $deviceToken,
'notification' => [
'title' => $title,
'body' => $body,
]
]

Sample Code that illustrates the problem

Logs taken while reproducing problem

No logs are produced

Workaround

Currently the work around is to

  1. Have the payload with the icon specified, I'm using the php framework to send messages and not certain if the payload structure is standardized across platforms. https://github.com/kreait/firebase-php/blob/master/docs/cloud-messaging.rst

[
'token' => $deviceToken,
'notification' => [
'title' => $title,
'body' => $body,
'icon' => 'notification_icon',
],
'android' => [
'ttl' => '3600s',
'priority' => 'normal',
'notification' => [
'icon' => 'notification_icon',
],
],

  1. Have the custom icon stored as a drawable with the following in config.xml

Note if the path used in the documentation is used (platforms/android/res/drawable/phonegap.png) then this will cause phonegap 8.0.0/cordova-android 7.0.0 to break with a file not found error
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#images

@macdonst
Copy link
Member

@charlesverge a couple of things for you to double check. First, it sounds like you are running into the Notification vs Data Payload issue. You'll need to put everything in data for this plugin to work properly.

Second, make sure your icon has some transparent pixels or you will get that grey square.

The final bit about paths being incorrect, is a docs bug. Thanks for bringing it to my notice.

@macdonst macdonst added the docs label Jul 11, 2018
@ghost
Copy link

ghost commented Aug 9, 2018

@charlesverge what is the correct image path for cordova 8?

@Lenndev
Copy link

Lenndev commented Aug 16, 2018

@maitscha i just fixed this in my app by doing this:

<platform name="android">
        <resource-file src="res/icon/android/push/drawable-mdpi/icon_push.png" target="app/src/main/res/drawable-mdpi/ic_stat_iconandroid.png" />
        <resource-file src="res/icon/android/push/drawable-hdpi/icon_push.png" target="app/src/main/res/drawable-hdpi/ic_stat_iconandroid.png" />
        <resource-file src="res/icon/android/push/drawable-xhdpi/icon_push.png" target="app/src/main/res/drawable-xhdpi/ic_stat_iconandroid.png" />
        <resource-file src="res/icon/android/push/drawable-xxhdpi/icon_push.png" target="app/src/main/res/drawable-xxhdpi/ic_stat_iconandroid.png" />
        <resource-file src="res/icon/android/push/drawable-xxxhdpi/icon_push.png" target="app/src/main/res/drawable-xxxhdpi/ic_stat_iconandroid.png" />
</platform>

then in the init of this plugin add

{ android: {
                icon: 'ic_stat_iconandroid',
                iconColor: '#<any_color_you_like--optional>',
  }
}

hope this helps (Anyone)

ATTENTION:
i used:

cordova 8.0.0
android 7.1.1
<plugin name="phonegap-plugin-push" spec="~2.2.3" />

@lock
Copy link

lock bot commented Sep 16, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants