应用研发平台EMAS中进程杀掉的前提下,收到辅助弹窗通知,在onSysNoticeOpened方法中怎么把推送内容给到flutter呢?
在应用研发平台EMAS中,当进程被杀掉后收到辅助弹窗通知,并希望在onSysNoticeOpened
方法中将推送内容传递给Flutter,可以按照以下步骤进行:
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL_NAME = "com.example.yourapp/sys_notice_opened";
private MethodChannel methodChannel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FlutterEngine flutterEngine = FlutterFragmentActivity.findFlutterView(this).getFlutterEngine();
methodChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL_NAME);
}
public void onSysNoticeOpened(Context context, String title, String content, Map<String, String> extraParams) {
// 调用Flutter的方法
Map<String, Object> messageData = new HashMap<>();
messageData.put("title", title);
messageData.put("content", content);
messageData.put("extraParams", extraParams);
methodChannel.invokeMethod("onSysNoticeOpened", messageData);
}
}
import 'package:flutter/services.dart';
class NotificationHelper {
static const MethodChannel _channel =
const MethodChannel('com.example.yourapp/sys_notice_opened');
static Future<void> handleSysNoticeOpened(Map<String, dynamic> message) async {
await _channel.invokeMethod('onSysNoticeOpened', message);
}
}
onSysNoticeOpened
方法中,调用NotificationHelper.handleSysNoticeOpened
方法并将通知内容传递给Flutter。public void onSysNoticeOpened(Context context, String title, String content, Map<String, String> extraParams) {
// 调用Flutter的方法
Map<String, Object> messageData = new HashMap<>();
messageData.put("title", title);
messageData.put("content", content);
messageData.put("extraParams", extraParams);
methodChannel.invokeMethod("onSysNoticeOpened", messageData);
}
onSysNoticeOpened
事件。import 'package:flutter/material.dart';
import 'package:your_app/notification_helper.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late MethodChannel _methodChannel;
void initState() {
super.initState();
_methodChannel = MethodChannel('com.example.yourapp/sys_notice_opened');
_setupNotificationListener();
}
void _setupNotificationListener() {
_methodChannel.setMethodCallHandler((call) async {
if (call.method == "onSysNoticeOpened") {
Map<String, dynamic> message = call.arguments;
String title = message["title"];
String content = message["content"];
Map<String, String> extraParams = message["extraParams"];
// 处理接收到的标题、内容和额外参数
// ...
}
});
}
// ...
}
这样,当用户点击辅助弹窗通知时,onSysNoticeOpened
方法会被调用,然后通过MethodChannel将通知内容传递给Flutter。在Flutter中,你可以根据需要处理这些信息,例如显示一个自定义的对话框或者更新应用程序的状态。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。