我正试图允许我的flutter应用程序在后台处理通知。我正在使用带有onesignal的推式通知,当我滑动我的应用程序并关闭它时,它不再调用onReceiveHandler。所以我读了有关NotificationExtenderService的内容: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-service
因此,我首先在MainActivity.java旁边的android> app> main> java> ..> NotificationsService.java中创建了一个类
并将其添加到android> app>主文件夹中的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>
因此,在不进行任何清理之后,我没有做任何其他工作,而是尝试运行我的应用程序以查看它是否未显示任何错误。
但是似乎无法识别类方法和东西:
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和本机代码进行通信。
答案 0 :(得分:0)
在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;
}
}