problem in push notificaton for android using JS API

Hi,

I am work on a gas application with back end less

I have created admin panel at web server for update a price using backend less Java script API.

The Price of gases updated .

Now I want to create Push notification for android and ios devices
because we have gas mobile app which shows current gas prices.

Whenever I update a price of gas the Push notification will generate for all aldroid and ios device.

I try the topic "Publishing a message as a push notification and

targeting specific group of devices" from back end less.

When I execute the JS code it didn’t create any push notification .

I also try to write response of push notification but it shows [object Object ] and page is continuously requesting .

That means there is a no response.

My Push notification code is as given below:


 var APPLICATION_ID = "<My application ID>",
 
SECRET_KEY = "<MY secret key>",
 
VERSION = "v1"; //default application version;
 
Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
 
 
 function pushNote()
 
 {
 
 var channel = "Krish App",
 
message = "Price Updated Successfully",
 
pubOps = null,
 
deliveryOps = new DeliveryOptions({
 
pushPolicy: "PUSHONLY",
 
pushBroadcast: "ANDROID"
 
});
 
var response = Backendless.Messaging.publish( channel, message, pubOps,
 
deliveryOps );
 
document.write(response);
 
 }
 

So , anybody can help me to solve this problem

Hi Safi!

At first, check if you properly configured app for sending push notifications:
http://backendless.com/documentation/messaging/js/messaging_push_notification_setup_androi.htm
http://backendless.com/documentation/messaging/js/messaging_push_notification_setup_ios.htm

At second, using

document.write(response);

is not a good practice.

To fix [object Object ] problem use:

document.write(JSON.stringify(response));

Regards,
Kate.

Hi,
I have read this content and create my project id for android .
Now in that example there is a code for Backendless.Messaging.registerDevice(…) method as GCMSenderID argument .
So, where i have to write this code and project id ?and how to call the function because in given link it is snap shot of code for registerDevice ( ) Method?
So, can u give me a code or any hint for how to write the registerDevice( ) Method code
Regards
Safi Belim

Hi, Safi!

The registerDevice() method should be executed on android/iOS device. Executing this request would register the device in your application. After that you’ll be able to see it in your messaging tab in console.
The best way to try and leaarn it is to use backendless code generation feature. In order to do that:

    Login to developers console Switch to code generation tab for Android

    Choose IDE you are common with ( Eclipse | IDEA )
    Choose “Sample chat” option and generate code
    Find class Defaults and paste your Google Project Number into it
    Connect device and run the project

After application runs, consider that it has been registered in backendless console. To do that go to Messaging -> Devices tab. If it's ok and you can see at least one registered device, try to send push notification through your JS code. Please, note that in generated code registerDevice() method is used in class ChooseNicknameActivity.

with best regards,
Alex Navara

Hi ,
Alex
I have created the code for android side as you mention. It works the push notification is generated but the message can’t displayed . It show a blank message in android device and at server side when i check the response of that function return value as given below

document.write(JSON.stringify(response));

the response shows as below:

{"errorMessage":null,"status":"published","messageId":"32E716F9-75E1-38E9-FF86-42E2B7785D00"}

so , is there any way to send the message perfectly what ever we write . I have use the code as above at first question.
Please help me
Regards
Safi

Hallo, Safi!

The thing is in how our generated code treates the recieved push notification.
Please, open class “PushReciever” in generated android project, and take a look at method onMessage().
It would not show any message if there is no tickerText ( because of “if” statement ). So, to recieve push notifications with our generated code, you should change your JS code: just change pubOps in your PushNote() function from null to:

pubOps = new PublishOptions(
    {
        headers: {
            "android-ticker-text": "ticker text",
            "android-content-title": "content title",
            "android-content-text": "content text"
        }
    }
)

After that try to send the push again - you should recieve the message now.
You can read more about headers here: http://backendless.com/documentation/messaging/js/messaging_publish_push_notifications.htm

with best regards,
Alex Navara

Safi!

I’d like to remind you that each push notification is associated with particular channel. By default, our generated android sample registers device in “default” channel. At the same time, your JS code sends push to channel “Krish App”. It’s not going to work. To fix this issue, consider that you’re sending push notification to the channel, where target device is registered.
You can change the channel in android sample in class “Defaults”.

best regards,
Alex Navara

Hi, I have change the channel make as default and also set the publish option as you describe above but i still get blank notificatio.
I forget to told you that we are using a Corona sdk for android development.
Is there any issue for backendless with corona

Hi, Safi!

Just to make it clear, can you answer me:

  1. You recieve emtpy notification on device, or you do not recieve it at all?
  2. After sending push, consider it the console that the sent push and the registered device are on the same channel. Is that true?
  3. Are you using our generated app now, or app on corona?

Thank you!

Hi, Safi,

Do you have some class in your application responsible for handling the received push notifications? I’m talking about some class like PushReceiver extending BackendlessBroadcastReceiver in the generated sample.

Hi,
Sorry but i check whatever you ask

  1. yes I receive empty push notification on all android devices
  2. we are using same channel that is default at both side
  3. we are creatinng app on corona 3
    Thank You

Hi, Our developer use a REST API at android side.
so our developer don’t have idea about that.
If there is any specific method in REST API then let me know.
Thank You

Hi, Safi!
If you recieve a notification on device, but you cannot see any content in it - than the problem is in the way you build the notification on your client side, on the device. Your android developer should review his code which recieves and handles push notifications and configure it to use our push structure. Probably, your current android code doesn’t expect to find push content in “android-ticker-text”, “android-content-title”, “android-content-text”. It looks for other names, but cannot find them, and as a reason it generates a push with all values set to null.
An example of handling you can find in generated code, on class “PushReciever”.

with best regards,
Alex Navara

To be sure I understood you correctly: your developer uses REST API for receiving push notifications?

Hi,
First of all thanks to helping me. the problem was solved yesterday.
i have set header as “alert”:“Data updated”. and it works.
So, Thank you again.
Now i want to publish push notification message for ios device so, can u tell me how can i do that???

Hi, Safi,
Try the solution described in this comment: http://support.backendless.com/t/problem-in-push-notificaton-for-android-using-js-api#comment-2053
Just add the following headers for iOS devices: “ios-alert”, “ios-badge”, “ios-sound”. And don’t forget to add “IOS” to DeliveryOptions’ pushBroadcast.
Again, you can read about headers (and sending push notifications from JS generally) in our documentation: http://backendless.com/documentation/messaging/js/messaging_publish_push_notifications.htm

I have done whatever u told but i can’t send the push notification to ios devices with android device
i have create two function one for android and another for ios and when the data update i calles both functions one by one . I have also check response of ios notification ehich shows message published but i can’t get any message.
The code of ios function as below

function pushios()
    {
        var channel = "default",
message = "Price Updated Successfully",
pubOps =  new PublishOptions(

{

headers: {

"ios-alert":"Gas Price Updated",
/*"ios-badge":"",*/
/*"ios-sound":URL string or array of bytes*/

}

}

),
deliveryOps = new DeliveryOptions({
pushPolicy: "PUSHONLY",
pushBroadcast: "IOS"
});
var response = Backendless.Messaging.publish( channel, message, pubOps,
deliveryOps );

/*document.write(JSON.stringify(response));*/
    }

Have you configured the backend per the instructions from here:

http://backendless.com/documentation/messaging/android/messaging_push_notification_setup_ios.htm