Flutter 背景为一个信号的颤振
我正在尝试允许我的颤振应用程序在后台处理通知。我将推送通知与onesignal一起使用,当我滑动并关闭应用程序时,它不再调用onReceiveHandler。所以我读到了NotificationExtender服务: 因此,首先我在android>app>main>java>。>NotificationsService.java中创建了一个类,位于MainActivity.java旁边 并将其添加到android>app>main文件夹中的AndroidMainfest.xml中:Flutter 背景为一个信号的颤振,flutter,onesignal,Flutter,Onesignal,我正在尝试允许我的颤振应用程序在后台处理通知。我将推送通知与onesignal一起使用,当我滑动并关闭应用程序时,它不再调用onReceiveHandler。所以我读到了NotificationExtender服务: 因此,首先我在android>app>main>java>。>NotificationsService.java中创建了一个类,位于MainActivity.java旁边 并将其添加到android>app>main文件夹中的AndroidMainfest.xml中: <s
<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>
显示以下错误:
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
那么问题出在哪里,或者这是一种错误的做法,我还必须为颤振创建一个方法通道和本机代码,以便在这种情况下进行通信。在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>
<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>
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;
}
}