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

Commit 8929990

Browse files
🐧 Fix Android O channel confusing name/description
1 parent 2f45c0d commit 8929990

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

docs/API.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@ PushNotification.createChannel(
203203
},
204204
{
205205
id: 'testchannel1',
206-
description: 'My first test channel',
206+
name: 'First channel',
207+
description: 'This is my very first notification channel',
207208
importance: 3,
208209
vibration: true
209210
}
210211
);
211212
```
212213

213-
The above will create a channel for your app. You'll need to provide the `id`, `description` and `importance` properties.
214+
The above will create a channel for your app. You'll need to provide the `id`, `name` and `importance` properties, `description` is optional. The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
214215

215216
A default channel with the id "PushPluginChannel" is created automatically. To make changes to the default channel's settings, create a channel with the id "PushPluginChannel" before calling the PushNotification.init function.
216217

@@ -219,7 +220,8 @@ A default channel with the id "PushPluginChannel" is created automatically. To m
219220
| Property | Type | Description |
220221
| -------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
221222
| `id` | `String` | The id of the channel. Must be unique per package. The value may be truncated if it is too long. |
222-
| `description` | `String` | The user visible name of the channel. The recommended maximum length is 40 characters; the value may be truncated if it is too long. |
223+
| `name` | `String` | The user visible name of the channel. The recommended maximum length is 40 characters; the value may be truncated if it is too long. |
224+
| `description` | `String` | The user visible description of the channel. The recommended maximum length is 300 characters; the value may be truncated if it is too long. |
223225
| `importance` | `Int` | The importance of the channel. This controls how interruptive notifications posted to this channel are. The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest. |
224226
| `sound` | `String` | The name of the sound file to be played upon receipt of the notification in this channel. Cannot be changed after channel is created. |
225227
| `vibration` | `Boolean` or `Array` | Boolean sets whether notification posted to this channel should vibrate. Array sets custom vibration pattern. Example - vibration: `[2000, 1000, 500, 500]`. Cannot be changed after channel is created. |

src/android/com/adobe/phonegap/push/PushConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public interface PushConstants {
9191
public static final String DEFAULT_CHANNEL_ID = "PushPluginChannel";
9292
public static final String CHANNELS = "channels";
9393
public static final String CHANNEL_ID = "id";
94+
public static final String CHANNEL_NAME = "name";
9495
public static final String CHANNEL_DESCRIPTION = "description";
9596
public static final String CHANNEL_IMPORTANCE = "importance";
9697
public static final String CHANNEL_LIGHT_COLOR = "lightColor";

src/android/com/adobe/phonegap/push/PushPlugin.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private JSONArray listChannels() throws JSONException {
6868
for (NotificationChannel notificationChannel : notificationChannels) {
6969
JSONObject channel = new JSONObject();
7070
channel.put(CHANNEL_ID, notificationChannel.getId());
71+
channel.put(CHANNEL_NAME, notificationChannel.getName());
7172
channel.put(CHANNEL_DESCRIPTION, notificationChannel.getDescription());
7273
channels.put(channel);
7374
}
@@ -94,9 +95,14 @@ private void createChannel(JSONObject channel) throws JSONException {
9495

9596
String packageName = getApplicationContext().getPackageName();
9697
NotificationChannel mChannel = new NotificationChannel(channel.getString(CHANNEL_ID),
97-
channel.optString(CHANNEL_DESCRIPTION, ""),
98+
channel.optString(CHANNEL_NAME, ""),
9899
channel.optInt(CHANNEL_IMPORTANCE, NotificationManager.IMPORTANCE_DEFAULT));
99100

101+
String desc = channel.optString(CHANNEL_DESCRIPTION, "");
102+
if(desc != null && !desc.isEmpty()) {
103+
mChannel.setDescription(desc);
104+
}
105+
100106
int lightColor = channel.optInt(CHANNEL_LIGHT_COLOR, -1);
101107
if (lightColor != -1) {
102108
mChannel.setLightColor(lightColor);
@@ -157,7 +163,8 @@ private void createDefaultNotificationChannelIfNeeded(JSONObject options) {
157163
}
158164
try {
159165
options.put(CHANNEL_ID, DEFAULT_CHANNEL_ID);
160-
options.putOpt(CHANNEL_DESCRIPTION, "PhoneGap PushPlugin");
166+
options.putOpt(CHANNEL_NAME, "PhoneGap PushPlugin");
167+
options.putOpt(CHANNEL_DESCRIPTION, "Default channel");
161168
createChannel(options);
162169
} catch (JSONException e) {
163170
Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());

src/js/push.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class PushNotification {
1818
this.handlers = {
1919
registration: [],
2020
notification: [],
21-
error: [],
21+
error: []
2222
};
2323

2424
// require options parameter

0 commit comments

Comments
 (0)