Skip to content

Commit 9f5c2fb

Browse files
author
weiry
committed
本地通知添加category、priority、builderName属性
1 parent e03b9a0 commit 9f5c2fb

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,47 @@ public void addLocalNotification(ReadableMap readableMap) {
539539
JSONObject notificationExtraJson = new JSONObject(notificationExtra.toHashMap());
540540
notification.setExtras(notificationExtraJson.toString());
541541
}
542+
543+
// 设置BuilderId
544+
if (readableMap.hasKey(JConstants.BUILDER_NAME)) {
545+
try {
546+
String layoutFileName = readableMap.getString(JConstants.BUILDER_NAME);
547+
if (!TextUtils.isEmpty(layoutFileName)) {
548+
// 通过布局文件名获取资源ID
549+
int builderId = reactContext.getResources().getIdentifier(
550+
layoutFileName,
551+
"layout",
552+
reactContext.getPackageName()
553+
);
554+
if (builderId != 0) {
555+
notification.setBuilderId(builderId);
556+
} else {
557+
JLogger.w("Layout file not found: " + layoutFileName);
558+
}
559+
}
560+
} catch (Exception e) {
561+
JLogger.w("Failed to set BuilderId: " + e.getMessage());
562+
}
563+
}
564+
565+
// 设置Category
566+
if (readableMap.hasKey(JConstants.CATEGORY)) {
567+
String category = readableMap.getString(JConstants.CATEGORY);
568+
if (!TextUtils.isEmpty(category)) {
569+
notification.setCategory(category);
570+
}
571+
}
572+
573+
// 设置Priority
574+
if (readableMap.hasKey(JConstants.PRIORITY)) {
575+
try {
576+
int priority = readableMap.getInt(JConstants.PRIORITY);
577+
notification.setPriority(priority);
578+
} catch (Exception e) {
579+
JLogger.w("Priority must be a number");
580+
}
581+
}
582+
542583
JPushInterface.addLocalNotification(reactContext, notification);
543584
}
544585

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public class JConstants {
7979
public static final String BSSID = "bssid";
8080
public static final String SSID = "ssid";
8181
public static final String CELL = "cell";
82+
83+
// 本地通知相关常量
84+
public static final String BUILDER_NAME = "builderName";
85+
public static final String CATEGORY = "category";
86+
public static final String PRIORITY = "priority";
8287
}

0 commit comments

Comments
 (0)