Sending Client Push Notification Via Button click in android

24 views
Skip to first unread message

Raul Morales Jr

unread,
Sep 2, 2016, 2:04:53 PM9/2/16
to back{4}app
Hey guys, I'm having issues trying to set this up. I'm a noob and still confused on how to implement this code. So far i am able to successfully send push notifications to devices via Back4app web push with no issues. Now i would like to set up a client push through button click for my chat app to notify users that a new message was sent in the app. So far from what i understand i have to upload the main.js to back4app cloudcode section seen in the attachment of this post.  Now i have no idea on how to call this in the app under the button click. So far i have this inside the button click. any help would greatly be appreciated. thanks in advance.

 HashMap<String, Object> params = new HashMap<String, Object>();
params.put("Message", message.getBody());
ParseCloud.callFunctionInBackground("push", params, new FunctionCallback<Float>() {
public void done(Float ratings, ParseException e) {
if (e == null) {


// ratings is 4.5
}
}
});

cloudcode.png

Davi Macêdo

unread,
Sep 12, 2016, 4:49:30 AM9/12/16
to back{4}app
Hi.

You have to write something like this:
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("channels", new String[]{ "Channel 1", "Channel 2" }); // The channels you want to send your push
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("alert", "your alert message here");
params.put("data", data });
ParseCloud.callFunctionInBackground("push", params, new FunctionCallback<Float>() {
    public void done(Float ratings, ParseException e) {
        if (e == null) {


            // ratings is 4.5
        }
    }
});

Best!
Reply all
Reply to author
Forward
0 new messages