11package me .youchai .rnpush ;
22
3+ import android .app .NotificationChannel ;
4+ import android .app .NotificationChannelGroup ;
35import android .app .NotificationManager ;
46import android .content .Context ;
57import android .content .Intent ;
2123import com .facebook .react .bridge .WritableMap ;
2224import com .facebook .react .modules .core .RCTNativeAppEventEmitter ;
2325
26+ import java .lang .reflect .Array ;
27+ import java .util .Arrays ;
2428import java .util .Collections ;
29+ import java .util .List ;
2530
2631import me .youchai .rnpush .utils .Logger ;
2732
@@ -104,6 +109,31 @@ public static void sendEvent(String key, WritableMap event) {
104109 }
105110 }
106111
112+ private void createNotificationChannel () {
113+ // Create the NotificationChannel, but only on API 26+ because
114+ // the NotificationChannel class is new and not in the support library
115+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
116+ // String description = getString(R.string.channel_description);
117+ int importance = NotificationManager .IMPORTANCE_DEFAULT ;
118+ NotificationChannelGroup customerGroup = new NotificationChannelGroup ("TODO" , "企业给员工的任务" );
119+ NotificationChannelGroup todoGroup = new NotificationChannelGroup ("Customer Dynamics" , "客户动态" );
120+
121+ NotificationChannel customerChannel = new NotificationChannel ("Customer Dynamics" , "客户动态通知" , importance );
122+ customerChannel .setGroup (customerGroup .getId ());
123+ NotificationChannel hignChannel = new NotificationChannel ("high_system" , "服务提醒" , importance );
124+ hignChannel .setGroup (customerGroup .getId ());
125+ NotificationChannel todoChannel = new NotificationChannel ("TODO" , "企业给员工的任务" , importance );
126+ todoChannel .setGroup (todoGroup .getId ());
127+ // channel.setDescription(description);
128+ // Register the channel with the system; you can't change the importance
129+ // or other notification behaviors after this
130+ NotificationManager notificationManager = __rac .getSystemService (NotificationManager .class );
131+ notificationManager .createNotificationChannelGroups (Arrays .asList (customerGroup , todoGroup ));
132+ notificationManager .createNotificationChannels (Arrays .asList (customerChannel , hignChannel ,todoChannel ));
133+
134+ }
135+ }
136+
107137 @ ReactMethod
108138 public void init (ReadableMap configs , Promise promise ) {
109139 ReadableMap config = null ;
@@ -114,9 +144,14 @@ public void init(ReadableMap configs, Promise promise) {
114144 this .pushService = PushServiceFactory .create (__rac , config );
115145 this .pushService .init ();
116146 RNPushModule .onNotificationAuthorization (__rac );
147+
117148 Logger .i ("init Success!" );
118149 promise .resolve (null );
150+
151+ createNotificationChannel ();
152+
119153 } catch (Throwable e ) {
154+ e .printStackTrace ();
120155 Logger .i ("error when init push service" + e .getMessage ());
121156 promise .reject (e );
122157 }
0 commit comments