feat: 支持command指令回调到业务层

This commit is contained in:
Liuyf 2025-02-21 09:25:36 +08:00
parent 12a3a36b71
commit aa93729f48
2 changed files with 10 additions and 2 deletions

View File

@ -303,11 +303,12 @@ public class JPushHelper {
} }
return extras; return extras;
} }
public static Map<String, Object> bundleToMap(Bundle bundle) { public static Map<String, Object> bundleToMap(Bundle bundle) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
if (bundle != null) { if (bundle != null) {
for (String key : bundle.keySet()) { for (String key : bundle.keySet()) {
if("intent_component".equals(key)||"intent_action".equals(key)){ if ("intent_component".equals(key) || "intent_action".equals(key)) {
continue; continue;
} }
Object value = bundle.get(key); Object value = bundle.get(key);
@ -316,6 +317,7 @@ public class JPushHelper {
} }
return map; return map;
} }
public Map<String, Object> stringToMap(String extra) { public Map<String, Object> stringToMap(String extra) {
Map<String, Object> useExtra = new HashMap<String, Object>(); Map<String, Object> useExtra = new HashMap<String, Object>();
try { try {

View File

@ -29,6 +29,8 @@ class JPush {
EventHandler? _onConnected; EventHandler? _onConnected;
EventHandler? _onInAppMessageClick; EventHandler? _onInAppMessageClick;
EventHandler? _onInAppMessageShow; EventHandler? _onInAppMessageShow;
EventHandler? _onCommandResult;
void setup({ void setup({
String appKey = '', String appKey = '',
bool production = false, bool production = false,
@ -141,6 +143,7 @@ class JPush {
EventHandler? onConnected, EventHandler? onConnected,
EventHandler? onInAppMessageClick, EventHandler? onInAppMessageClick,
EventHandler? onInAppMessageShow, EventHandler? onInAppMessageShow,
EventHandler? onCommandResult,
}) { }) {
print(flutter_log + "addEventHandler:"); print(flutter_log + "addEventHandler:");
@ -152,11 +155,12 @@ class JPush {
_onConnected = onConnected; _onConnected = onConnected;
_onInAppMessageClick = onInAppMessageClick; _onInAppMessageClick = onInAppMessageClick;
_onInAppMessageShow = onInAppMessageShow; _onInAppMessageShow = onInAppMessageShow;
_onCommandResult = onCommandResult;
_channel.setMethodCallHandler(_handleMethod); _channel.setMethodCallHandler(_handleMethod);
} }
Future<dynamic> _handleMethod(MethodCall call) async { Future<dynamic> _handleMethod(MethodCall call) async {
print(flutter_log + "_handleMethod:"); print(flutter_log + "_handleMethod: ${call.method}");
switch (call.method) { switch (call.method) {
case "onReceiveNotification": case "onReceiveNotification":
@ -176,6 +180,8 @@ class JPush {
return _onInAppMessageClick!(call.arguments.cast<String, dynamic>()); return _onInAppMessageClick!(call.arguments.cast<String, dynamic>());
case "onInAppMessageShow": case "onInAppMessageShow":
return _onInAppMessageShow!(call.arguments.cast<String, dynamic>()); return _onInAppMessageShow!(call.arguments.cast<String, dynamic>());
case "onCommandResult":
return _onCommandResult!(call.arguments.cast<String, dynamic>());
default: default:
throw new UnsupportedError("Unrecognized Event"); throw new UnsupportedError("Unrecognized Event");
} }