Skip to content

Commit 2fc2e2c

Browse files
committed
添加 android重要通道设置
1 parent f888476 commit 2fc2e2c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

android/src/main/java/me/youchai/rnpush/RNPushModule.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.youchai.rnpush;
22

3+
import android.app.NotificationChannel;
4+
import android.app.NotificationChannelGroup;
35
import android.app.NotificationManager;
46
import android.content.Context;
57
import android.content.Intent;
@@ -21,7 +23,10 @@
2123
import com.facebook.react.bridge.WritableMap;
2224
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
2325

26+
import java.lang.reflect.Array;
27+
import java.util.Arrays;
2428
import java.util.Collections;
29+
import java.util.List;
2530

2631
import 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
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yocdev/react-native-notification",
3-
"version": "1.0.25",
3+
"version": "1.0.26",
44
"author": "npm@youchai.me",
55
"license": "MIT",
66
"description": "react-native notification",

0 commit comments

Comments
 (0)