Push Notifications

Hi Backendlesses,

trying to send push notifications from my android app.

done everthing to register the app and I can see the device I’m using in the devices at the pub \ sub monitor.

copied the simplest syntax from the documentary but it crashes the app:

MessageStatus status = Backendless.Messaging.publish( “hello world!” );
thought it might be because I need to do it Async, but the other syntax from the documentry is filled with errors and won’t compile:public void Backendless.Messaging.publish( “hello world!”, AsyncCallback<MessageStatus> responder )what am I doing wrong ?
thanks,Gil.

Hi Gil,

You need to include special headers into the call in order to make it a push notification:
https://backendless.com/documentation/messaging/rest/messaging_publish_push_notifications.htm

Regards,
Mark

thanks Mark. actually I’m following you webinar so I’m using the headers now.
but for some reason, changing to the code from the webinar gives me an error when trying to register the device. it says that “Device does not have package com.google.android.gsf”.
it’s odd, the devices was registered before I copied the code from the webinar.

Are you using simulator or a real device?
Here is a similar problem: http://stackoverflow.com/questions/11339445/com-google-android-gsf-package-couldnt-be-found

I’m using both my galaxy note 4 and an emulator.

my code for registering the device is :

gcmSenderID = "bla bla not showing it here";

Backendless.Messaging.registerDevice(gcmSenderID, new AsyncCallback&lt;Void&gt;() {
    @Override
    public void handleResponse(Void aVoid) {
        Toast.makeText(FeedActivity.this, "registered", Toast.LENGTH_LONG).show();

    }

    @Override
    public void handleFault(BackendlessFault backendlessFault) {
        Toast.makeText(FeedActivity.this, backendlessFault.toString(), Toast.LENGTH_LONG).show();

    }
});

but it gives me that error. I was registered before so I’m not sure where’s the problem.

OK Sergey you were right. I used an older AVD that wasn’t with google API services.

now the device is registered, but crashes when I try to send a push notification.

first, I need to know: I’m registering the device in my MainActivity and then send the push notification from another activity. do I need to write the registration code in all my activities \ screens or only one of them ?

second, this is the code that crashes:


PublishOptions publishOptions = new PublishOptions();
HashMap&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
headers.put("alert-text", "push for android");
headers.put("android-ticker-text", "You just got a push notification!");
headers.put("android-content-title", "This is a notification title");
headers.put("android-content-text", "Push Notifications are cool");
publishOptions.setHeaders(headers);

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushPolicy(PushPolicyEnum.ONLY);
deliveryOptions.setPushBroadcast( PushBroadcastMask.ANDROID );

Backendless.Messaging.publish( "Hi Devices!", publishOptions, deliveryOptions );

thanks!!!

What error or exception do you receive on crash?

I’ve fixed the problem. the publish was crushing because it wasn’t Async.

now I get this response: onItemClick: MessageStatus{messageId=‘6AEFF1FC-49BE-D150-FFDF-96B090345100’, status=SCHEDULED}

why is it scheduled ? how can I make it push right away… ?

OK,

I’ve solved everything. I can send push notifications.
now my challange is this: how do I send a push notification to the people who follow the user.

each user has a “one to many” property with the emails of the followers. I need to send the push to them. but I have no clue how to do it with the logic of sending and receiving the push notifications in Backendless.

please help.

Please open a separate topic for any new question

how did u make it push the notification right away? i m having the same prob.