I have setup Push notifications in my Worklight 6.3 hybrid app which was working fine in my Android device until few days back. I didn't make any changes to the app after that. Now when I try to send notification, I get the result as '{"isSuccessful":true,"result": "Notification sent to user :: admin"}'.
Neither do I see notifications on my device, nor I see any error messages. I also get the 'onSuccess' callback called when WL.Client.Push.subscribe API is executed
From your description its seems like the message is sent to GCM and the
question we need to ask is why it's not arriving the device.
1)Can you please reinstall the application and then try to send push notification?
If it will work you may have a problem with the device subscription.
2)can you paste here the logcat - maybe we can find something there...
3)Did you try to receive the push when the phone is on WiFi?
If possible please try to check it on a different network.
Sometimes GCM is slow and you might get a notification after about 5 to 10 mins.
if we get isSuccessful":true,"result": "Notification sent to user :: admin
then from worklight end we have done everything right and GCM has also accepted the notification to be sent.
I will know more once you will upload the additional information
Related
When testing to the android app from the firebase console the status of the messages says completed and shows the delivery date. How do we check whether a message has sent to the receipts and delivered in an android app with fire-base: https://console.firebase.google.com?
I am working on a firebase quickstart app to test push notification message to my target users. Please help me.
#SaikCaskey have an insight of the solution of your question, though I do not agree on some points.
The push notification is not guaranteed to be received to your targeted user actually. Push notification might fail for several reason. But that's not the issue here. You might get notifications even if your application is in background or stopped. You need to start your FirebaseMessagingService with START_STICKY. This behaviour might differ in different devices too. Some devices allows/disallow this behaviour of receiving push notification when your app is stopped.
So, if you need to log when your user has received the push notification, you might get it in a bit complex way. When your device will come online you'll get the push and in your onMessageReceived function you can get the System.Clock for getting the time of notification received. Then create an instance of Firebase and then set the time to the reference node of the user's notification delivery time.
Hope that helps!
With a fresh install app on my Samsung Note 5 device and also on my emulator, some notifications was sent via the Firebase console are received properly on those 2 devices.
But after a day, my emulator was reopened, my phone was reconnected to the Wifi, I started creating some few notification messages on Firebase console again, but those devices did not receive any message from Firebase.
I turned off and turned on my phone's Wifi, then the phone received those notifications. I turned on and turned off plane mode on my emulator, then the emulator received those notifications. Is there something wrong with my app? Or with Firebase? (I already use WAKE_LOCK permission). Any suggestion?
Thanks!
It seems to work fine now after I changed my device's Wifi connection.
From #AL's comment:
There might be a chance that the Android device is connected to the
Wifi, but your Wifi needs something like a refresh for the internet
connection to work again, which is the same case for the devices
connected to it.
I still not sure why, but his comment make this works.
Great to know that, #AL gave a hint of the problem and you got it working too. I'm here for putting some of my thoughts here regarding your issue.
As you've worked with push notification already, I think you know pretty much about how this works actually. If you want a short brief, you might take a look at this answer.
Now, you already have known, you need to get a push registration ID from FCM when your application starts. This push registration ID, is the unique ID by which FCM knows when and how to send you a push notification. This push registration ID doesn't change every time you launch your application, but yes, it changes some times. When your push registration ID has been changed, but you couldn't get your new push registration ID from FCM, the push notification won't work properly in that time. This is usually a network issue though, but don't panic if that happens.
Another thing I need to point out is, push notification is not always guaranteed to be received in your device/devices. So if you're performing some action when a push notification is received in your application, you might need to make the action fail safe too (e.g. you might consider polling after a certain time if no push is received).
On the server side, I am using GCM server 1.0.2 library provided by Google. On the client side, I set up GCM as provided on the official documentation.
My problem is that everything works fine on most devices, but on few devices, push is not recieved.
if (case1)
message = new Message.Builder()
.timeToLive(0)
.collapseKey("0")
.delayWhileIdle(false)
.addData("msg", msg).build();
else if (case2)
message = new Message.Builder()
.collapseKey("2")
.addData("msg", msg).build();
else
message = new Message.Builder().addData("msg", msg).build();
Result result = sender.sendNoRetry(message, regId);
System.out.println("Message ID:"+result.getMessageId());
System.out.println("Failed:" + result.getErrorCodeName());
From what I can see from tests with the above code, there are no error. The message id is present, but error code name is null(which is a sign of successful push).
I've tried almost every setting. Tested with TTL, collapse key, delay while idle set on and off.
What are some cases that can cause to block(?) GCM push? And how can I resolve this?
EDIT
I have no idea why but the temporary solution below solved my problem.
In GcmIntentService#onHandleIntent just remove
GcmBroadcastReceiver.completeWakefulIntent(intent);
This line releases the wakeful service. I am curious though because on other devices, push messages are sent continuously even when this line was not removed.
This is not a solution because this document states that I should call completeWakeFulIntent after each work. Also, my method will drain the battery significantly.
Any suggestion?
Make sure you've set your SENDER ID you've received from Google correctly.
Make sure your device was registered with Google's GCM service correctly.
Make sure you are sending the push to the correct reg id you've received from Google. and that you didn't receive an error from Google GCM service.
Have you set the delay_while_idle = 1? This means the message won't reach the device if it's idle (off, offline, locked screen, etc...). Change it to delay_while_idle = 0 if you want your wakelock permission to make any difference. Please read more here.
Some times it takes time for the push to arrive (but never too much time, then there is a problem). Check what's the "time to live" of the push you've sent.
Do you have the correct version of the Playstore to receive the notification ?
Are you logged with a functional Google Account on those devices ?
I also had a problem when I "Force stop" an app, you can't receive notification on any app after a "force stop" (start with android 3.1) so be careful with that too.
if you are using wifi, may be the internet firewall block the gcm. try to use internet with your mobile sim card.
Checklist
Make sure Google Play Store is updated to latest version
Make sure there are no systemwide settings for notifications which are blocking
Go into app in Application Manager and uncheck/recheck 'Notifications'
If on Wifi, switch Wifi connection to a different AP (if possible)
Reboot the device
Install 'Push Notification Fixer' (install this anyway)
First-run notification setup can be annoyingly arbitrary and require the device be 'kicked' in one or more of these ways.
I have an app built for iOS and Android which has push notifications. Everything is working great however I was wondering if there is a way to store the data of the push notification in the app so that when users launch the app after receiving a notification I can show them the message again?
Basically I allow users to share information and/or chat amongst their friends. If they receive a notification when the app is in the background it comes through as a normal push message but when they launch the app I would like to direct them to the chat feature to see the message again.
I am storing the messages sent in a remote DB but seeing as they have already received the payload it doesn't make much sense for the app to call the remote DB to retrieve the same message.
I am using Distriqt's extensions in AS3 and Air 3.5.
Cheers
I asked Distriqt's support for the same thing a few weeks ago and they explained that there is no way to get the information of the push notification message while the app is closed so they suggested this :
- when the user opens the app, you call your server to check if they haven't missed anything, and get the data from there. If there has been a push, you display the push message as if it was received with the app in the foreground.
It's a bit tricky and not very satisfying but it works.. As long as the user follows the path.
If your user receives the push and chooses not to open your app, he will still get the push message in your app next time he opens it.
I was having trouble figuring this out too but I found a solution! Basically if a user launches an app (not running in the background) by way of a notification it comes through in the Invoke event, not the usual Notification event. So do this:
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
private function invoked(evt:InvokeEvent):void
{
if (evt.reason == InvokeEventReason.NOTIFICATION)
{
var payload:Object = Object(evt.arguments[0]);
// do stuff
}
}
That's pretty much it. There's more detail in this blog post here: http://blogs.adobe.com/airodynamics/2012/05/29/push-notifications-support-in-ios/
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
doesn't work correctly for Android push notification. Android starts with InvokeEventReason.standard all the time, so we cant receive message. It works only for iOS.
I am developing Android app using GCM. Currently I am using standard Google libs on client and server sides.
If I am testing on two Android devices GCM works fine when both devices switched on regardless if my app is running or not.
However if Device A is switched off and I am sending messages to it from Device B, when Device A switched back on it doesn't receive any messages been sent while it was off line.
On server side (which initiates an actual send) every message to Device A has no collapse_key, time_to_live is set to 2000000 (just in case for testing purposes). Actual send has retries parameter set to 50 (in case GCM itself is unreachable, however this is unlikely).
Do I need to complete the GCM registration procedure on device boot? Currently I do so.
Please note that GCM broadcast receiver and GCMIntentService were set as well as permissions
in manifest as described on Google web site.
Any advice will be much appreciated. I really got stuck with this issue.
Sorry guys. It was my fault. Shared preferences were not loaded properly, that caused GCMIntentService to operate unproperly. Messages go in fine.
So SOLVED
Do I need to complete the GCM registration procedure on device boot?
No, you don't.
In our project we don't have any problems with receiving messages which was sent while device was switched off or ofline. We don't use any google libraries and done all as described at gcm homepage Also, we don't set any collapse_key and time_to_live for our messages.
By the way, do you process message_type? My be GCM notify you that message was deleted