如何阻止Android上的Onesignal推送通知?

问题描述 投票:4回答:1

我知道我可以在Broadcast OnReceive()收到它们,但我不能阻止Onesignal创造一个Notification

android onesignal
1个回答
7
投票

您将需要设置OneSignal NotificationExtenderService类并将其作为AndroidManifest.xml添加到您的Service

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文档。

© www.soinside.com 2019 - 2024. All rights reserved.