我希望在手机上发生特定事件时(例如收到预定格式的短信或来自特定电话号码的短信),弹出通知(并在单击后打开应用程序)。目前,我使用flutter SMS package,在main()中构建SmsReceiver类的实例,并尝试将短信正文打印到控制台:
void main() {
SmsReceiver receiver = new SmsReceiver();
receiver.onSmsReceived.listen((SmsMessage msg) => print(msg.body));
runApp(MyApp());
}
我在真实设备(三星Galaxy 8+)上测试了代码。当应用程序在前台或后台运行时,我可以轻松获取短信内容。然而,当我关闭应用程序并收到短信时,控制台会打印以下错误信息:W/FlutterJNI(23977): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: plugins.babariviere.com/recvSMS. Response ID: 0。你能帮我解决这个问题吗?即使应用程序已关闭,是否有可能监听此类事件并触发通知?附注:我查看了flutter local notifications。但是,看起来该软件包仅安排通知出现。在我的情况下,我希望通知是事件驱动的。