onNotification method not called - android

I am trying to use Ionic Push for Push Notifications. I have successfully registered with the server and got the Token ID also (Called reg_id in Ionic).
I have followed all the steps as shown in Ionic Docs here http://docs.ionic.io/v1.0/docs/push-install.
But now when I try to send push notifications using the curl command, the notification is shown as sent but is never received by the app. If I check the status, I get the status as success. Please help
Comtroller Code: https://gist.github.com/samarthagarwal/833064a2de0660e826b6
Any suggestions are highly appreciated.

Related

How to send message from Firebase to device when app is killed? [duplicate]

This question already has answers here:
Android app not receiving Firebase Notification when app is stopped from multi-task tray
(6 answers)
Closed 6 years ago.
I am trying to get familiar with Firebase Notifications. It works fine, but I am stuck with receiving messages from the notification console when the app is not turned on.
I know that documentation says that:
if your app in foreground or background you can receive message in onMessageReceived method, otherwise user will receive notification in tray... click on it will open main activity with data inside intent
But is there are any way to catch every message from the notification console even if the application is closed?
==== ANSWER ====
Find answer here
There is no way to send data message from the notification console.
But there are other ways to send notification to devices and they will be caught inside onMessageReceived!
You can use terminal (Mac or Linux) or some service like Postman to send Post request on this link: https://fcm.googleapis.com/fcm/send
with the next body:
{
"to": "/topics/your_topic_here",
"data": {
"text":"text",
"text1":"text1",
...
}
}
also you need to add 2 headers:
Authorization - key=your_server_key_here
Content-Type - application/json
To get your server key, you can find it in the firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key
onMessageReceived() method will not be called if the app is in background or killed only when the message is sent through Firebase Console.
When app is not running you will anyway receive notification from firebase console. But if you want to intercept data via onMessageReceived() then you will have to create a custom app server which will send only data payload to fcm endpoint. In short you will have to create an app server if you want to actually utilize FCM more efficiently in this case .
You can have a look at these two questions which discuss more regarding same and in second question I also discuss briefly over using node.js and java servlet to do the same:
Handle the data payload without user tapping on the notification?
How to push notification to client when Firebase has a new entry?
Do let me know if this provides you with some info.

Bluemix push notification for android is not sending any notifications

I'm trying to use the sample code available here: https://github.com/ibm-bluemix-mobile-services/bms-samples-android-hellopush
And the first difficulty I found was on configuring the GCM - it seems that somethings changed since it was documented - anyway I guess I got everything configured correctly.
I got the app working and I'm able to register my device, but there is no notification when I try to send it. I'm using both the bluemix dashboard and the swagger to send a message. The response I get is that the message was sent, but I got nothing on the device (a mobile phone, not the emulator).
I checked my Google API dashboard, and there is no activity on the GCM api.
The application ID is: f97eb706-3375-438d-8221-cd7ac0266de1
I was using Postman to test the GCM API (https://android.googleapis.com/gcm/send) and I was getting an "Error 401 Unauthorized". I tried to create a new API Key, but without success.
After reading this: https://stackoverflow.com/a/22453025/6828416
I tried to create a new project on GCM, and it suddenly started to work.
The Docs are currently being updated for GCM, so that will be fixed very soon.
I attempted to recreate your problem and just tested out the sample with Push Notifications with the Android sample here (with the latest version of Android Studio v2.1.3):
Before:
After:
Here is how I edited my code snippets after cloning the sample (mock values):
Code Edit 1 Before:
BMSClient.getInstance().initialize(this, "<APPLICATION_ROUTE>", "<APPLICATION_ID>", BMSClient.REGION_US_SOUTH);
Code Edit 1 After:
BMSClient.getInstance().initialize(this, "http://imfpush.ng.bluemix.net", "dfadsfadsfdsf-2343-2334-8e82-421c02ce847c", BMSClient.REGION_US_SOUTH);
Code Edit 2 Before:
push.initialize(this, "<APPLICATION_ID>", "<CLIENT_SECRET>");
Code Edit 2 After:
push.initialize(this, "dfadsfadsfdsf-2343-2334-8e82-421c02ce847c", "edec64df-34fd-44e3-9d1e-dfsfsdf989899");
I got these values from the Push Notifications service credentials (mock values).
Here is how I set up GCM:
In my Bluemix config, it looks something like this (mock values):
Here's how I got those values from GCM (mock values):
Sender ID:
API Key:
#Paulo For new projects the dashboard is not coming up to enable GCM API in https://console.developers.google.com.
Steps to enable GCM:
Create New Project->create API Key->Enable GCM.
To Enable GCM please Navigate to Dashboard tab and search for Google Cloud Messaging-> Click on GCM and enable the API. Please wait for 5 min to get it activate.
Configure the GCM credentials for Push Notification-> register the device and send notification.

payload is null from server

In my app receives the push notification from GCM(for android) everything is fine am getting the notification but the payload is null. Cross checked server side script it's fine. This is the response am getting in callback method
This is the GCM response
{"type":"callback",
"source":{"pushType":"gcm", "invocationAPIs":[],
"showAppOnTrayClick":true,
singleCallback":false,
"__propertiesDefined__":true,
"bubbleParent":true,
"_events":{"callback":{},
"trayClickLaunchedApp":{},
"trayClickFocusedApp":{}},
"focusAppOnPush":false,
"enabled":false,
"showTrayNotificationsWhenFocused":false,
"apiName":"Ti.Module",
"showTrayNotification":true,"debug":false},
"payload":"","bubbles":false,
"cancelBubble":false}
Am using Titanium 3.5.1GA and tried with ti.cloudpush(3.3.7) same issues .
How can i solve it?
Since the notification does arrive it's probably not an error in the app but on the server sending the payload. Try one of the several (online) apps to test notifications on Google.

Android PushNotification From Json URL

I have a Json URL, which contains data about Latest Job Postings, I am successfully parsing the Json URL and able to display the top job postings in my ListView.
But my requirement is to create a push notification, so that whenever a new job is posted, the user should be able to get a notification on device.
I have followed this: http://www.vogella.com/articles/AndroidNotifications/article.html
But I don't know how to get notifications in my case.
Could anyone help me?
Issue:
Give push notification to user's device about the updated data even when application is in background mode.
Solution:
Upon successful insertion of new data in your database (which is going to give updated set of data to your JSON request) , just call the file which send GCM push notification to all your users.
Reference:
GCM docs
GCM push-notification using php server
In context of implementation presented in demo app of 2nd link,
upon successful insertion,you can call send_message.php file,but make sure that $regId and $message should be retrieved from your database
You have created ActionBar Notifications for your app, but now you need to create the ability to receive notifications from a web client, instead of going to find them yourself from the URL.
To create a push notification you would need to have a constant thread (BroadcastReceiver) on the device that is waiting for the notification from the sever.
Google 'Cloud to Device Messaging' is the simplest way to do this.
This is a good link with lots of info on how to do this :
http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android/
If you require these notifications to be displayed on the device even when the application is not running (which seems to be the case from what you describe), you can use Google Cloud Messaging.
You would need a server that would poll the Json URL for updates, and send a GCM message to all the devices where your app is installed once such an update is detected.
Your app would have to register to Google Cloud Messaging and send the Registration ID received from Google to your server.
When your app receive a GCM message, you would create a notification and when the notification is tapped, you would start the activity that loads the data from the JSON URL.

GCM android, Push Notifications not being recieved

I am working on an android app that will recieve push notifications from the GCM server.
I am using php as the 3rd-party server.
I've a few questions.
When I send request to gcm server from my php script it gives me the following response
{"multicast_id":8799227316277290616,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1341388064110557%5d17b789f9fd7ecd"}]}
Now the response seems fine but you can see a % sign in the message_id. Is that ok? if it's not than how am I able to recieve the correct message_ID?
When I use json_decode in my php script and echo this multicastid it gives me something like this
8.7992273162773E+18
and I am sure it will give the same type of value when I'll echo message_id also. So why it is not echoing the correct value?
My last question is that when I send this request which seems right and open my android application there is no notification there. Is it caused by the above errors or there is some other problem?
I had a similar issue with C2DM. The reason was that the android app name was not the same for which I requested the quota. It got fixed once the corrected the package name.
In my case, android application was not running so the push notifications can't be received. I started the app and then I could receive messages.

Categories

Resources