Sending push-notifications through parse do not show up on Android - wrong format?

Hey everyone,

I am trying to set up push-notifications for the android version of our ionic app (using Parse-JS-SDK) with back4app.com . I’ve followed the guides and set up firebase and checked from over there that notifications work and show up (they do). However, when I try to sent them over Parse - either the dashboard or via cURL - I can’t see them. My cURL:

curl -X POST \
  -H "X-Parse-Application-Id: XXXX" \
  -H "X-Parse-Master-Key: XXXX" \
  -H "Content-Type: application/json" \
  -d '{
        "where": {
          "deviceType": {                          
            "$in": [                                             
              "ios",                               
              "android"
            ]
          }
        },
        "data":{
          "title": "Yeah", "badge": 1, "body": "content"
          }
      }'\  https://parseapi.back4app.com/parse/push

Putting the app in foreground, and alerting the content, I can see that they differ in structure from the firebase-own version:

Firebase version:

Parse data:

It looks like the parse-server is not unwrapping the data (instead it is converted to a string?) but instead puts it into another data-field. Dropping the data-wrap from the cURL just gives an empty notification.

What am I doing wrong? How does it work for others? Did I overlook a setting or do I need to post the content differently? Any hints appreciated!

Would you mind to share the code that you are using to alert the push content in the app?

Thanks for the response,

as said I am currently using the REST-Interface via cURL (with the code above) and the dashboard-UI for sending push messages. The later I tried both text and JSON formatted, but neither yields a notification that shows up - which is weird enough as the dashboard UI renders some previews what that is supposed to look like…

Do you think it would be different when issuing from cloud-code? I can try that if you want.

I’ve read the code and noticed that the notification-key is just pushed over, and hear, hear, if use that instead of data in my cURL, I see the message pop up!

curl -X POST \
  -H "X-Parse-Application-Id: APPKEY" \
  -H "X-Parse-Master-Key: MASTERKEY" \
  -H "Content-Type: application/json" \
  -d '{
        "where": {
          "deviceType": "android"
        },
        "notification": {
          "title": "Title", 
          "body": "All work and no play makes Jack a dull boy."
        }
      }'\  https://parseapi.back4app.com/parse/push  

Now, just to make sure it also works with cloud-code :smiley: .

Cool. I’m glad you figured it out. But I believe it should work with your original curl command. I was asking to see the code you have on the client side to alert the push. Maybe the problem can be fixed over there.

Okay,

so, now running JS-code in the parse-server (of a docker, but back4app shows the same). I am able to send push-notifications with the notifications:-field, but am seeing the same problem of data as before.

Doing:

const title = `Test Title`;
const body = "Body!";

return Parse.Push.send({
    channels: ["jG32TpFYxh:news"],
    data: {
      title,
      body,
      android: {
        notification: {
          icon: 'stock_ticker_update',
          color: '#7e55c3'
        }
      },
    }
}, { useMasterKey: true });

It does show up in the notifications are and the console.log, shows that data is converted to a string and put inside data - which is incorrect.
image


I’ve also played around with other ways, including other fields in notification, but neither that nor any other fields seem to work at all. Unfortunately, notification doesn’t fully support all features that data is supposed to (e.g. mediaURL), but only title and body.

Is there anywhere production code I could look at? I really don’t get what I am doing wrong…

You may have some code in your client side that receives the push and shows it in the alert, right? Would you mind to share this piece of code?

I replaced the alert with a console.log, but sure:


import { Plugins, PushNotificationToken } from '@capacitor/core';
const { PushNotifications, Device } = Plugins;

// ...
PushNotifications.addListener('pushNotificationReceived', (x) => console.log("received", x));

I am using capacitor for that. This only reacts if the app is in foreground when the message is received and regardless of the content won’t show in the notification area.

I now see, what you were getting at. Trying the firebase message creator, I am able to send a message with the extra image (just an https one though), that shows up in the notification area, but when I look at what capacitor hands over, there is no reference of it at all (second is the data given, when the message is clicked):
image

geee…

So, it seems to be an ugly debug-view problem. This shows up and also shows the image to me now:

const title = `Test Title`;
const body = "Body!";
const image = "http://192.168.0.117:1337/parse/files/APPLICATION_ID/636614d63f114e40bbfebf77b9b5519b_yaz-huge.jpg";

return Parse.Push.send({
    channels: ["jG32TpFYxh:news"],
    content_available: 1,
    notification: {
      image, title, body
    }
}, { useMasterKey: true });
1 Like