Skip to content

Commit abac69e

Browse files
author
何家祥
committed
动态产生channel
1 parent 0a5a3d0 commit abac69e

File tree

4 files changed

+78
-152
lines changed

4 files changed

+78
-152
lines changed

android/build.gradle

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
buildscript {
22
repositories {
3+
gradlePluginPortal()
34
google()
45
jcenter()
5-
maven {url 'http://developer.huawei.com/repo/'}
6+
mavenCentral()
7+
maven { url 'https://developer.huawei.com/repo/'}
68
}
79

810
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.4.0'
10-
classpath 'com.huawei.agconnect:agcp:1.5.2.300'
11+
classpath 'com.android.tools.build:gradle:7.4.0'
12+
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
1113
}
1214
}
1315

1416
apply plugin: 'com.android.library'
1517

1618
android {
17-
1819
compileSdkVersion 28
1920
buildToolsVersion "28.0.3"
20-
2121
defaultConfig {
2222
minSdkVersion 17
2323
targetSdkVersion 28
@@ -31,29 +31,27 @@ android {
3131

3232
repositories {
3333
google()
34-
maven { url 'http://developer.huawei.com/repo/' }
34+
maven {url 'https://developer.huawei.com/repo/'}
3535
mavenCentral()
3636
}
3737

3838
dependencies {
39-
compile fileTree(dir: "libs", include: ["*.jar"])
39+
implementation fileTree(dir: "libs", include: ["*.jar"])
4040

41-
compile 'cn.jiguang.sdk:jcore:2.9.0'
42-
compile 'cn.jiguang.sdk:jpush:4.3.0'
41+
implementation 'cn.jiguang.sdk:jpush:5.0.3'
4342

44-
compile 'cn.jiguang.sdk.plugin:xiaomi:4.3.0'
43+
implementation 'cn.jiguang.sdk.plugin:xiaomi:5.0.3'
4544

46-
compile 'com.huawei.hms:push:5.3.0.304'
47-
compile 'com.huawei.agconnect:agconnect-core:1.5.2.300'
45+
implementation 'com.huawei.hms:push:6.10.0.300'
46+
implementation 'cn.jiguang.sdk.plugin:huawei:5.0.3'
4847

49-
compile 'cn.jiguang.sdk.plugin:huawei:4.3.0'
5048

51-
compile 'cn.jiguang.sdk.plugin:oppo:4.3.0'
49+
implementation 'cn.jiguang.sdk.plugin:oppo:5.0.3'
5250

53-
compile 'cn.jiguang.sdk.plugin:vivo:4.3.0'
51+
implementation 'cn.jiguang.sdk.plugin:vivo:5.0.3'
5452

55-
compile 'com.facebook.react:react-native:+'
53+
implementation 'com.facebook.react:react-native:+'
5654
}
5755

58-
56+
apply plugin: 'com.huawei.agconnect'
5957

android/src/main/AndroidManifest.xml

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838

3939
<application>
4040

41-
<!-- jpush -->
42-
<!-- since 3.3.0 Required SDK 核心功能-->
43-
<!-- 可配置android:process参数将PushService放在其他进程中 -->
44-
<!--User defined. For test only 继承自cn.jpush.android.service.JCommonService-->
4541
<service
4642
android:name="cn.jpush.android.service.JCommonService"
4743
android:enabled="true"
@@ -51,7 +47,6 @@
5147
<action android:name="cn.jiguang.user.service.action" />
5248
</intent-filter>
5349
</service>
54-
5550
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->
5651
<!--since 3.3.0 接收JPush相关事件-->
5752
<receiver
@@ -64,109 +59,6 @@
6459
</intent-filter>
6560
</receiver>
6661

67-
<!-- Rich push 核心功能 since 2.0.6 -->
68-
<activity
69-
android:name="cn.jpush.android.ui.PopWinActivity"
70-
android:exported="true"
71-
android:theme="@style/MyDialogStyle">
72-
<intent-filter>
73-
<category android:name="android.intent.category.DEFAULT" />
74-
75-
<action android:name="cn.jpush.android.ui.PopWinActivity" />
76-
77-
<category android:name="${JPUSH_PKGNAME}" />
78-
</intent-filter>
79-
</activity>
80-
81-
<!-- Required SDK核心功能 -->
82-
<activity
83-
android:name="cn.jpush.android.ui.PushActivity"
84-
android:configChanges="orientation|keyboardHidden"
85-
android:exported="true"
86-
android:theme="@android:style/Theme.NoTitleBar">
87-
<intent-filter>
88-
<action android:name="cn.jpush.android.ui.PushActivity" />
89-
90-
<category android:name="android.intent.category.DEFAULT" />
91-
<category android:name="${JPUSH_PKGNAME}" />
92-
</intent-filter>
93-
</activity>
94-
95-
<!-- since 3.5.0 Required SDK 核心功能 -->
96-
<!-- 3.5.0新增,用于定时展示功能 -->
97-
<receiver
98-
android:name="cn.jpush.android.service.SchedulerReceiver"
99-
android:exported="false" />
100-
101-
<!-- since 3.0.9 Required SDK 核心功能 -->
102-
<provider
103-
android:name="cn.jpush.android.service.DataProvider"
104-
android:authorities="${JPUSH_PKGNAME}.DataProvider"
105-
android:exported="false"
106-
android:process=":pushcore" />
107-
<!-- since 3.1.0 Required SDK 核心功能 -->
108-
<provider
109-
android:name="cn.jpush.android.service.DownloadProvider"
110-
android:authorities="${JPUSH_PKGNAME}.DownloadProvider"
111-
android:exported="true" />
112-
113-
<!-- since 3.3.0 Required SDK核心功能 -->
114-
<activity
115-
android:name="cn.jpush.android.service.JNotifyActivity"
116-
android:exported="true"
117-
android:taskAffinity="jpush.custom"
118-
android:theme="@android:style/Theme.Translucent.NoTitleBar">
119-
<intent-filter>
120-
<action android:name="cn.jpush.android.intent.JNotifyActivity" />
121-
122-
<category android:name="android.intent.category.DEFAULT" />
123-
124-
<category android:name="${applicationId}" />
125-
</intent-filter>
126-
</activity>
127-
<!-- since 3.5.6 新增华硕通道 -->
128-
<receiver
129-
android:name="cn.jpush.android.asus.AsusPushMessageReceiver"
130-
android:exported="false" />
131-
132-
<!-- Required SDK 核心功能 -->
133-
<!-- 可配置android:process参数将PushService放在其他进程中 -->
134-
<service
135-
android:name="cn.jpush.android.service.PushService"
136-
android:enabled="true"
137-
android:exported="false"
138-
android:process=":pushcore">
139-
<intent-filter>
140-
<action android:name="cn.jpush.android.intent.REGISTER" />
141-
<action android:name="cn.jpush.android.intent.REPORT" />
142-
<action android:name="cn.jpush.android.intent.PushService" />
143-
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
144-
</intent-filter>
145-
</service>
146-
147-
<!-- Required SDK核心功能 -->
148-
<receiver
149-
android:name="cn.jpush.android.service.PushReceiver"
150-
tools:node="replace"
151-
android:enabled="true">
152-
<intent-filter android:priority="1000">
153-
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <!-- Required 显示通知栏 -->
154-
<category android:name="${applicationId}" />
155-
</intent-filter>
156-
<intent-filter>
157-
<action android:name="android.intent.action.USER_PRESENT" />
158-
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
159-
</intent-filter>
160-
<!-- Optional -->
161-
<intent-filter>
162-
<action android:name="android.intent.action.PACKAGE_ADDED" />
163-
<action android:name="android.intent.action.PACKAGE_REMOVED" />
164-
165-
<data android:scheme="package" />
166-
</intent-filter>
167-
</receiver>
168-
169-
<!-- Required SDK核心功能 -->
17062
<receiver
17163
android:name="cn.jpush.android.service.AlarmReceiver"
17264
android:exported="false" />

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public WritableMap toWritableMap() {
6565
map.putString("title", title);
6666
map.putString("content", content);
6767
map.putString("extras", extras);
68-
6968
return map;
7069
}
7170
}

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

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import com.facebook.react.bridge.ReactContextBaseJavaModule;
2121
import com.facebook.react.bridge.ReactMethod;
2222
import com.facebook.react.bridge.ReadableMap;
23+
import com.facebook.react.bridge.ReadableMapKeySetIterator;
2324
import com.facebook.react.bridge.WritableMap;
2425
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
2526

2627
import java.lang.reflect.Array;
28+
import java.util.ArrayList;
2729
import java.util.Arrays;
2830
import java.util.Collections;
2931
import java.util.List;
@@ -109,31 +111,6 @@ public static void sendEvent(String key, WritableMap event) {
109111
}
110112
}
111113

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-
137114
@ReactMethod
138115
public void init(ReadableMap configs, Promise promise) {
139116
ReadableMap config = null;
@@ -148,7 +125,7 @@ public void init(ReadableMap configs, Promise promise) {
148125
Logger.i("init Success!");
149126
promise.resolve(null);
150127

151-
createNotificationChannel();
128+
//createNotificationChannel();
152129

153130
} catch (Throwable e) {
154131
e.printStackTrace();
@@ -294,6 +271,66 @@ public void checkPermission(Promise promise) {
294271
promise.resolve(state);
295272
}
296273

274+
/**
275+
* config:{
276+
* [groupId]:{
277+
* name,
278+
* channelDic:{
279+
* [channelId]:{
280+
* name,
281+
* importance,
282+
* }
283+
* }
284+
* }
285+
* }
286+
* @param config
287+
* @param promise
288+
*/
289+
@ReactMethod
290+
public void createNotificationChannels(ReadableMap config, Promise promise){
291+
try{
292+
if(config == null){
293+
promise.resolve(null);
294+
return;
295+
}
296+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
297+
// String description = getString(R.string.channel_description);
298+
// int importance = NotificationManager.IMPORTANCE_DEFAULT;
299+
ReadableMapKeySetIterator iterator = config.keySetIterator();
300+
ArrayList groups = new ArrayList<NotificationChannelGroup>();
301+
ArrayList channels = new ArrayList<NotificationChannel>();
302+
while(iterator.hasNextKey()){
303+
String groupId = iterator.nextKey();
304+
ReadableMap groupConfig = config.getMap(groupId);
305+
String groupName = groupConfig.getString("name");
306+
ReadableMap channelDic = groupConfig.getMap("channelDic");
307+
NotificationChannelGroup group = new NotificationChannelGroup(groupId,groupName);
308+
ReadableMapKeySetIterator cIt = channelDic.keySetIterator();
309+
groups.add(group);
310+
while(cIt.hasNextKey()){
311+
String channelId = cIt.nextKey();
312+
ReadableMap channelConfig = channelDic.getMap(channelId);
313+
String channelName = channelConfig.getString("name");
314+
int importance = channelConfig.getInt("importance");
315+
NotificationChannel channel = new NotificationChannel(channelId,channelName,importance);
316+
channel.setGroup(group.getId());
317+
channels.add(channel);
318+
}
319+
}
320+
321+
// Register the channel with the system; you can't change the importance
322+
// or other notification behaviors after this
323+
NotificationManager notificationManager = __rac.getSystemService(NotificationManager.class);
324+
notificationManager.createNotificationChannelGroups(groups);
325+
notificationManager.createNotificationChannels(channels);
326+
}
327+
promise.resolve(null);
328+
}catch(Throwable e){
329+
e.printStackTrace();
330+
promise.reject(e);
331+
}
332+
}
333+
297334
@ReactMethod
298335
public void checkNetwork(Promise promise) {
299336
try {

0 commit comments

Comments
 (0)