diff --git a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java index e4bbbcc..225b36e 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +++ b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java @@ -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; @@ -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); diff --git a/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java b/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java index aedd38f..08e2b43 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java +++ b/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java @@ -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"; //电话号码 diff --git a/example/package.json b/example/package.json index 07baf64..ebf0a5c 100644 --- a/example/package.json +++ b/example/package.json @@ -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" diff --git a/index.js b/index.js index daaea28..bf1c422 100644 --- a/index.js +++ b/index.js @@ -677,6 +677,13 @@ export default class JPush { // setupWithOpion } } + static setChannelAndSound(params) { + if (Platform.OS == "android") { + JPushModule.setChannelAndSound(params) + } else { + // setupWithOpion + } + } //***************************************iOS Only*************************************** diff --git a/package.json b/package.json index ad42bad..d3dddb5 100644 --- a/package.json +++ b/package.json @@ -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"