gpt4 book ai didi

在后台使用 OneSignal PushNotifications 进行抖动

转载 作者:行者123 更新时间:2023-12-04 13:40:27 25 4
gpt4 key购买 nike

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

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

并将其添加到 android>app>main 文件夹中的 AndroidMainfest.xml 中:

<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>

因此,在没有做任何其他工作的情况下,我尝试运行我的应用程序,只是为了查看在执行完 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;
}
}

显示以下错误:
error: cannot find symbol
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
^
symbol: class OSNotificationReceivedResult
location: class OneSignalSilentNotificationHandler
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Finished with error: Gradle task assembleDebug failed with exit code 1

那么问题出在哪里,或者这是错误的做法,我是否还必须为 flutter 创建一个方法 channel 和 native 代码以在这种情况下进行通信。

最佳答案

在 AndroidMainfest.xml 中,里面:

<service
android:name=".OneSignalNotificationExtender"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>

在 android>app>main>java>..> 我在 MainActivity.java 旁边创建 OneSignalNotificationExtender.java

OneSignalNotificationExtender.java:
import com.onesignal.OSNotificationPayload;
import com.onesignal.OSNotificationReceivedResult;
import com.onesignal.NotificationExtenderService;

public class OneSignalNotificationExtender extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
if (receivedResult != null) {




}

// Returning true tells the OneSignal SDK you have processed the notification and not to display it's own.
return false;
}

}

关于在后台使用 OneSignal PushNotifications 进行抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57959616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com