diff --git a/docs/API.md b/docs/API.md index 0b1a9ea86..61bec73bb 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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. @@ -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. | diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 9b4656a00..8dcda34ba 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -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"; diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java index 690b37776..7e7276e1d 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.java +++ b/src/android/com/adobe/phonegap/push/PushPlugin.java @@ -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); } @@ -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); @@ -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()); diff --git a/src/js/push.js b/src/js/push.js index f952cacbf..092f4a691 100644 --- a/src/js/push.js +++ b/src/js/push.js @@ -18,7 +18,7 @@ class PushNotification { this.handlers = { registration: [], notification: [], - error: [], + error: [] }; // require options parameter