"Advanced" notification options?

Hello, I am trying to get my push notifications to work using the native push plugin (phonegap). Right now I somewhat have it working. I can:

  • Show notifications while I am inside my app using an alert
  • Show notification on my start screen but only when it is off

Right now I am missing the following:

  • Notification showing while I am using other apps, for example Google Chrome app
  • Notification triggering the screen of my device, when a notification is send I want the screen to turn on, I know this can be done because I have other apps (like WhatsApp) that do this all the time but this is not happening with the Push plugin.

This is my code (straight from the docs):

this.checkPermission();

      const options: PushOptions = {
        android: {
            senderID: '123456'
        },
        ios: {
            alert: 'true',
            badge: false,
            sound: 'true'
        },
        windows: {}
    };

      const pushObject: PushObject = this.push.init(options);

      pushObject.on('notification').subscribe((notification: any) => alert(notification.message));
      
      pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));
      
      pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));



  checkPermission(){
    this.push.hasPermission()
    .then((res: any) => {
  
      if (res.isEnabled) {
        console.log('We have permission to send push notifications');
        this.createChannel();
      } else {
        console.log('We do not have permission to send push notifications');
      }
  
    });
  }

  createChannel(){
    this.push.createChannel({
      id: "testchannel1",
      description: "My first test channel",
      // The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
      importance: 3
     }).then(() => console.log('Channel created'));
  }

Can, what I want, be done? Do I need to configure something to get this done?

Thanks in advance.

1 Like

Hi @Nubdienub, could you tell me how did you implemented it in order notifications show in the app while open? For me works when I’m in other apps or when the device is blocked but not when the app is open, whish you could help me, my code:

// “app.component.ts” inside initializeApp() after this.platform.ready()

this.push.hasPermission()
.then((res: any) => {

        if (res.isEnabled) {
        console.log("We have permission to send push notifications");

        this.push.createChannel({
            id: "myChannel",
            description: "Notification channel",
            importance: 5
        }).then(() => console.log("Channel created"));
        } else {
            console.log("We do not have permission to send push notifications");
        }
    });

    const options: PushOptions = {
        android: {
        senderID: "12345678",
        vibrate: true,
        forceShow: true
        },
        ios: {
        alert: true,
        badge: true,
        sound: true
        },
        windows: {},
        browser: {
            pushServiceURL: "http://push.api.phonegap.com/v1/push"
        }
    };

    const pushObject: PushObject = this.push.init(options);


    pushObject.on("notification").subscribe(
        (notification: any) => {
            console.log("Received a notification", notification.message);
            alert(notification);
        }
    );

    pushObject.on("registration").subscribe(
        (registration: any) => {
            console.log("Device registered", registration);
            alert(registration.registrationId);
        }
    );

    pushObject.on("error").subscribe(
        error => {
            console.error("Error with Push plugin", error);
        }
    );

Registration id alert works and shows as well.
Platform: android 8.1.0