如何在 Android 上阻止 Onesignal 推送通知?
How to block Onesignal push notifications on Android?
我知道我可以在 Broadcast
OnReceive()
中收到它们,但我无法阻止 Onesignal 创建 Notification
.
您需要设置一个 OneSignal NotificationExtenderService
class 并将其作为 Service
添加到您的 AndroidManifest.xml
。
import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;
public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
// Read properties from result.
// Returning true tells the OneSignal SDK you have processed the notification and not to display it's own.
return true;
}
}
AndroidManifest.xml
<service
android:name=".NotificationExtenderBareBonesExample"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
有关详细信息,请参阅 OneSignal Android Background Data and Notification Overriding 文档。
我知道我可以在 Broadcast
OnReceive()
中收到它们,但我无法阻止 Onesignal 创建 Notification
.
您需要设置一个 OneSignal NotificationExtenderService
class 并将其作为 Service
添加到您的 AndroidManifest.xml
。
import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;
public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
// Read properties from result.
// Returning true tells the OneSignal SDK you have processed the notification and not to display it's own.
return true;
}
}
AndroidManifest.xml
<service
android:name=".NotificationExtenderBareBonesExample"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
有关详细信息,请参阅 OneSignal Android Background Data and Notification Overriding 文档。