Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block Onesignal push notifications on Android?

I know I can receive them in Broadcast OnReceive() but I cannot prevent Onesignal for creating a Notification.

like image 353
Majstor Avatar asked Mar 12 '23 08:03

Majstor


1 Answers

You will need to setup a OneSignal NotificationExtenderService class and add it to your AndroidManifest.xml as a 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>

See the OneSignal Android Background Data and Notification Overriding documentation for more details.

like image 55
jkasten Avatar answered Mar 19 '23 23:03

jkasten