@@ -56,6 +56,24 @@ private Context getApplicationContext() {
56
56
return this .cordova .getActivity ().getApplicationContext ();
57
57
}
58
58
59
+ @ TargetApi (26 )
60
+ private JSONArray listChannels () throws JSONException {
61
+ JSONArray channels = new JSONArray ();
62
+ // only call on Android O and above
63
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
64
+ final NotificationManager notificationManager = (NotificationManager ) cordova .getActivity ()
65
+ .getSystemService (Context .NOTIFICATION_SERVICE );
66
+ List <NotificationChannel > notificationChannels = notificationManager .getNotificationChannels ();
67
+ for (NotificationChannel notificationChannel : notificationChannels ) {
68
+ JSONObject channel = new JSONObject ();
69
+ channel .put (CHANNEL_ID , notificationChannel .getId ());
70
+ channel .put (CHANNEL_DESCRIPTION , notificationChannel .getDescription ());
71
+ channels .put (channel );
72
+ }
73
+ }
74
+ return channels ;
75
+ }
76
+
59
77
@ TargetApi (26 )
60
78
private void deleteChannel (String channelId ) {
61
79
// only call on Android O and above
@@ -358,6 +376,17 @@ public void run() {
358
376
}
359
377
}
360
378
});
379
+ } else if (LIST_CHANNELS .equals (action )) {
380
+ // un-subscribing for a topic
381
+ cordova .getThreadPool ().execute (new Runnable () {
382
+ public void run () {
383
+ try {
384
+ callbackContext .success (listChannels ());
385
+ } catch (JSONException e ) {
386
+ callbackContext .error (e .getMessage ());
387
+ }
388
+ }
389
+ });
361
390
} else {
362
391
Log .e (LOG_TAG , "Invalid action : " + action );
363
392
callbackContext .sendPluginResult (new PluginResult (PluginResult .Status .INVALID_ACTION ));
0 commit comments