6
6
import android .content .ContentResolver ;
7
7
import android .content .Context ;
8
8
import android .content .Intent ;
9
+ import android .graphics .Color ;
9
10
import android .media .AudioAttributes ;
10
11
import android .os .Build ;
11
12
import android .os .Bundle ;
@@ -47,6 +48,8 @@ public class PushNotifications extends Plugin {
47
48
public static String CHANNEL_IMPORTANCE = "importance" ;
48
49
public static String CHANNEL_VISIBILITY = "visibility" ;
49
50
public static String CHANNEL_SOUND = "sound" ;
51
+ public static String CHANNEL_USE_LIGHTS = "lights" ;
52
+ public static String CHANNEL_LIGHT_COLOR = "lightColor" ;
50
53
51
54
public static Bridge staticBridge = null ;
52
55
public static RemoteMessage lastMessage = null ;
@@ -192,6 +195,8 @@ public void createChannel(PluginCall call) {
192
195
channel .put (CHANNEL_VISIBILITY , call .getInt (CHANNEL_VISIBILITY , NotificationCompat .VISIBILITY_PUBLIC ));
193
196
channel .put (CHANNEL_IMPORTANCE , call .getInt (CHANNEL_IMPORTANCE ));
194
197
channel .put (CHANNEL_SOUND , call .getString (CHANNEL_SOUND , null ));
198
+ channel .put (CHANNEL_USE_LIGHTS , call .getBoolean (CHANNEL_USE_LIGHTS , false ));
199
+ channel .put (CHANNEL_LIGHT_COLOR , call .getString (CHANNEL_LIGHT_COLOR , null ));
195
200
createChannel (channel );
196
201
call .success ();
197
202
} else {
@@ -223,6 +228,8 @@ public void listChannels(PluginCall call) {
223
228
channel .put (CHANNEL_IMPORTANCE , notificationChannel .getImportance ());
224
229
channel .put (CHANNEL_VISIBILITY , notificationChannel .getLockscreenVisibility ());
225
230
channel .put (CHANNEL_SOUND , notificationChannel .getSound ());
231
+ channel .put (CHANNEL_USE_LIGHTS , notificationChannel .shouldShowLights ());
232
+ channel .put (CHANNEL_LIGHT_COLOR , String .format ("#%06X" , (0xFFFFFF & notificationChannel .getLightColor ())));
226
233
Log .d (getLogTag (), "visibility " + notificationChannel .getLockscreenVisibility ());
227
234
Log .d (getLogTag (), "importance " + notificationChannel .getImportance ());
228
235
channels .put (channel );
@@ -238,8 +245,17 @@ public void listChannels(PluginCall call) {
238
245
private void createChannel (JSObject channel ) {
239
246
if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .O ) {
240
247
NotificationChannel notificationChannelChannel = new NotificationChannel (channel .getString (CHANNEL_ID ), channel .getString (CHANNEL_NAME ), channel .getInteger (CHANNEL_IMPORTANCE ));
241
- notificationChannelChannel .setDescription (channel .getString (CHANNEL_DESCRIPTION , "" ));
242
- notificationChannelChannel .setLockscreenVisibility (channel .getInteger (CHANNEL_VISIBILITY , 0 ));
248
+ notificationChannelChannel .setDescription (channel .getString (CHANNEL_DESCRIPTION ));
249
+ notificationChannelChannel .setLockscreenVisibility (channel .getInteger (CHANNEL_VISIBILITY ));
250
+ notificationChannelChannel .enableLights (channel .getBool (CHANNEL_USE_LIGHTS ));
251
+ String lightColor = channel .getString (CHANNEL_LIGHT_COLOR );
252
+ if (lightColor != null ) {
253
+ try {
254
+ notificationChannelChannel .setLightColor (Color .parseColor (lightColor ));
255
+ } catch (IllegalArgumentException ex ) {
256
+ Log .e (getLogTag (), "Invalid color provided for light color." );
257
+ }
258
+ }
243
259
String sound = channel .getString (CHANNEL_SOUND , null );
244
260
if (sound != null && !sound .isEmpty ()) {
245
261
AudioAttributes audioAttributes = new AudioAttributes .Builder ()
0 commit comments