小编ino*_*noi的帖子

在后台使用 OneSignal PushNotifications 进行 Flutter

我试图让我的扑动应用程序在后台处理通知。我正在使用带有 onesignal 的推送通知,当我滑动我的应用程序并关闭它时,它不再调用 onReceiveHandler 。所以我读到了NotificationExtenderService: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-service

所以首先我在 android>app>main>java>..>NotificationsService.java 中创建了一个类,位于 MainActivity.java 旁边

并将其添加到 AndroidMainfest.xml 中,该文件位于 android>app>main 文件夹中:

<service
   android:name=".YOUR_CLASS_NAME"
   android:permission="android.permission.BIND_JOB_SERVICE"
   android:exported="false">
   <intent-filter>
      <action android:name="com.onesignal.NotificationExtender" />
   </intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)

因此,在没有做任何其他工作的情况下,我尝试运行我的应用程序,只是为了看看它在完成 flutter clean 等操作后是否没有显示任何错误。

但它似乎无法识别类方法和内容:

import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;

public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
   @Override
   protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
      // Read properties from result.

      // Return true to stop the notification from displaying.
      return false;
   }
}
Run Code Online (Sandbox Code Playgroud)

显示以下错误:

error: cannot find symbol
 protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
                                            ^
  symbol:   class OSNotificationReceivedResult
  location: …
Run Code Online (Sandbox Code Playgroud)

onesignal flutter

5
推荐指数
1
解决办法
3633
查看次数

标签 统计

flutter ×1

onesignal ×1