Skip to content

Commit 5a49236

Browse files
authored
Merge pull request #920 from LcTerry/master
开放:setChannelAndSound
2 parents 165e11e + 8fa1908 commit 5a49236

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
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
//电话号码

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"jcore-react-native": "2.1.3",
11-
"jpush-react-native": "2.9.9",
11+
"jpush-react-native": "3.0.0",
1212
"react": "16.8.6",
1313
"react-native": "0.60.5",
1414
"update": "^0.7.4"

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***************************************

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "index.d.ts",
77
"license": "ISC",
88
"author": "wicked.tc130",
9-
"version": "2.9.9",
9+
"version": "3.0.0",
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/jpush/jpush-react-native"

0 commit comments

Comments
 (0)