Skip to content

Commit db35edd

Browse files
committed
开放:setChannelAndSound
1 parent 165e11e commit db35edd

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

android/src/main/java/cn/jiguang/plugins/push/JPushModule.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
package cn.jiguang.plugins.push;
3-
3+
import android.app.NotificationChannel;
4+
import android.app.NotificationManager;
5+
import android.net.Uri;
6+
import android.os.Build;
47
import android.app.Activity;
58
import android.app.Application;
69
import android.os.Bundle;
@@ -97,6 +100,32 @@ public void setChannel(ReadableMap readableMap) {
97100
}
98101
}
99102
@ReactMethod
103+
public void setChannelAndSound(ReadableMap readableMap) {
104+
if (readableMap == null) {
105+
JLogger.w(JConstants.PARAMS_NULL);
106+
return;
107+
}
108+
String channel = readableMap.getString(JConstants.CHANNEL);
109+
String sound = readableMap.getString(JConstants.SOUND);
110+
String channelId = readableMap.getString(JConstants.CHANNELID);
111+
try {
112+
NotificationManager manager= (NotificationManager) reactContext.getSystemService("notification");
113+
if(Build.VERSION.SDK_INT<26){
114+
return;
115+
}
116+
if(TextUtils.isEmpty(channel)||TextUtils.isEmpty(channelId)){
117+
return;
118+
}
119+
NotificationChannel channel1=new NotificationChannel(channelId,channel, NotificationManager.IMPORTANCE_HIGH);
120+
if(!TextUtils.isEmpty(sound)){
121+
channel1.setSound(Uri.parse("android.resource://"+reactContext.getPackageName()+"/raw/"+sound),null);
122+
}
123+
manager.createNotificationChannel(channel1);
124+
JPushInterface.setChannel(reactContext,channel);
125+
}catch (Throwable throwable){
126+
}
127+
}
128+
@ReactMethod
100129
public void setBadgeNumber(ReadableMap readableMap) {
101130
if (readableMap == null) {
102131
JLogger.w(JConstants.PARAMS_NULL);

android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class JConstants {
88

99
public static final String CODE = "code";
1010
public static final String CHANNEL = "channel";
11+
public static final String CHANNELID = "channelId";
12+
public static final String SOUND = "sound";
1113
public static final String SEQUENCE = "sequence";
1214
public static final String CONNECT_ENABLE = "connectEnable";
1315
//电话号码

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ export default class JPush {
677677
// setupWithOpion
678678
}
679679
}
680+
static setChannelAndSound(params) {
681+
if (Platform.OS == "android") {
682+
JPushModule.setChannelAndSound(params)
683+
} else {
684+
// setupWithOpion
685+
}
686+
}
680687

681688

682689
//***************************************iOS Only***************************************

0 commit comments

Comments
 (0)