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

View File

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