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

Commit

Permalink
🐧 Fix Android O channel confusing name/description
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebeaumont committed Oct 29, 2018
1 parent 2f45c0d commit 8929990
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 5 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ PushNotification.createChannel(
},
{
id: 'testchannel1',
description: 'My first test channel',
name: 'First channel',
description: 'This is my very first notification channel',
importance: 3,
vibration: true
}
);
```

The above will create a channel for your app. You'll need to provide the `id`, `description` and `importance` properties.
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.

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.

Expand All @@ -219,7 +220,8 @@ A default channel with the id "PushPluginChannel" is created automatically. To m
| Property | Type | Description |
| -------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | `String` | The id of the channel. Must be unique per package. The value may be truncated if it is too long. |
| `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. |
| `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. |
| `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. |
| `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. |
| `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. |
| `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. |
Expand Down
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public interface PushConstants {
public static final String DEFAULT_CHANNEL_ID = "PushPluginChannel";
public static final String CHANNELS = "channels";
public static final String CHANNEL_ID = "id";
public static final String CHANNEL_NAME = "name";
public static final String CHANNEL_DESCRIPTION = "description";
public static final String CHANNEL_IMPORTANCE = "importance";
public static final String CHANNEL_LIGHT_COLOR = "lightColor";
Expand Down
11 changes: 9 additions & 2 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private JSONArray listChannels() throws JSONException {
for (NotificationChannel notificationChannel : notificationChannels) {
JSONObject channel = new JSONObject();
channel.put(CHANNEL_ID, notificationChannel.getId());
channel.put(CHANNEL_NAME, notificationChannel.getName());
channel.put(CHANNEL_DESCRIPTION, notificationChannel.getDescription());
channels.put(channel);
}
Expand All @@ -94,9 +95,14 @@ private void createChannel(JSONObject channel) throws JSONException {

String packageName = getApplicationContext().getPackageName();
NotificationChannel mChannel = new NotificationChannel(channel.getString(CHANNEL_ID),
channel.optString(CHANNEL_DESCRIPTION, ""),
channel.optString(CHANNEL_NAME, ""),
channel.optInt(CHANNEL_IMPORTANCE, NotificationManager.IMPORTANCE_DEFAULT));

String desc = channel.optString(CHANNEL_DESCRIPTION, "");
if(desc != null && !desc.isEmpty()) {
mChannel.setDescription(desc);
}

int lightColor = channel.optInt(CHANNEL_LIGHT_COLOR, -1);
if (lightColor != -1) {
mChannel.setLightColor(lightColor);
Expand Down Expand Up @@ -157,7 +163,8 @@ private void createDefaultNotificationChannelIfNeeded(JSONObject options) {
}
try {
options.put(CHANNEL_ID, DEFAULT_CHANNEL_ID);
options.putOpt(CHANNEL_DESCRIPTION, "PhoneGap PushPlugin");
options.putOpt(CHANNEL_NAME, "PhoneGap PushPlugin");
options.putOpt(CHANNEL_DESCRIPTION, "Default channel");
createChannel(options);
} catch (JSONException e) {
Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/js/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PushNotification {
this.handlers = {
registration: [],
notification: [],
error: [],
error: []
};

// require options parameter
Expand Down

0 comments on commit 8929990

Please sign in to comment.