flutter 如何在一个信号抖动中处理后台通知?

2wnc66cl  于 2023-01-21  发布在  Flutter
关注(0)|答案(1)|浏览(129)

我已经实现了onesignal在其文档中提到的notificationServiceExtension,但现在我无法在一个信号中运行后台通知处理程序。我已经在main activity中实现了以下代码:::

package com.example.just_normal

import com.onesignal.OneSignal
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

private val methodchannel = "background/notification";

class MainActivity: FlutterActivity() {
    
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        OneSignal.OSRemoteNotificationReceivedHandler { context, osNotificationReceivedEvent ->
             val CHANNEL : MethodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger , methodchannel)
            CHANNEL.invokeMethod("onBackgroundNotification" , osNotificationReceivedEvent);
            // osNotificationReceivedEvent.complete(null);
        }
   }

}

在上面的代码中,我试图在后台收到通知后立即调用flutter方法。我如何在后台收到通知后立即运行flutter方法。请帮助...

gudnpqoy

gudnpqoy1#

在应用程序中注册onesignal的init函数中使用此函数:
设置通知将显示在前景处理程序((操作系统通知接收事件){事件完成(事件通知);});
现在你将能够得到通知,即使当应用程序被杀死。

相关问题