Skip to content

Commit

Permalink
Merge pull request #920 from LcTerry/master
Browse files Browse the repository at this point in the history
开放:setChannelAndSound
  • Loading branch information
LcTerry authored Jul 25, 2023
2 parents 165e11e + 8fa1908 commit 5a49236
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
31 changes: 30 additions & 1 deletion android/src/main/java/cn/jiguang/plugins/push/JPushModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

package cn.jiguang.plugins.push;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.net.Uri;
import android.os.Build;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
Expand Down Expand Up @@ -97,6 +100,32 @@ public void setChannel(ReadableMap readableMap) {
}
}
@ReactMethod
public void setChannelAndSound(ReadableMap readableMap) {
if (readableMap == null) {
JLogger.w(JConstants.PARAMS_NULL);
return;
}
String channel = readableMap.getString(JConstants.CHANNEL);
String sound = readableMap.getString(JConstants.SOUND);
String channelId = readableMap.getString(JConstants.CHANNELID);
try {
NotificationManager manager= (NotificationManager) reactContext.getSystemService("notification");
if(Build.VERSION.SDK_INT<26){
return;
}
if(TextUtils.isEmpty(channel)||TextUtils.isEmpty(channelId)){
return;
}
NotificationChannel channel1=new NotificationChannel(channelId,channel, NotificationManager.IMPORTANCE_HIGH);
if(!TextUtils.isEmpty(sound)){
channel1.setSound(Uri.parse("android.resource://"+reactContext.getPackageName()+"/raw/"+sound),null);
}
manager.createNotificationChannel(channel1);
JPushInterface.setChannel(reactContext,channel);
}catch (Throwable throwable){
}
}
@ReactMethod
public void setBadgeNumber(ReadableMap readableMap) {
if (readableMap == null) {
JLogger.w(JConstants.PARAMS_NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class JConstants {

public static final String CODE = "code";
public static final String CHANNEL = "channel";
public static final String CHANNELID = "channelId";
public static final String SOUND = "sound";
public static final String SEQUENCE = "sequence";
public static final String CONNECT_ENABLE = "connectEnable";
//电话号码
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"jcore-react-native": "2.1.3",
"jpush-react-native": "2.9.9",
"jpush-react-native": "3.0.0",
"react": "16.8.6",
"react-native": "0.60.5",
"update": "^0.7.4"
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,13 @@ export default class JPush {
// setupWithOpion
}
}
static setChannelAndSound(params) {
if (Platform.OS == "android") {
JPushModule.setChannelAndSound(params)
} else {
// setupWithOpion
}
}


//***************************************iOS Only***************************************
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "index.d.ts",
"license": "ISC",
"author": "wicked.tc130",
"version": "2.9.9",
"version": "3.0.0",
"repository": {
"type": "git",
"url": "https://github.com/jpush/jpush-react-native"
Expand Down

0 comments on commit 5a49236

Please sign in to comment.