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).
Related
On Android, I have been experiencing long push delay in some devices (minutes, half an hour). Seems like the device is asleep (but not for WhatsApp). Even on Pre-Marshmallow devices.
After a while they don't respond to push.
I have created a simple app (copied Google's Cloud Messaging client sample).
Tried to send push via The Firebase Console, setting priority to HIGH and made sure it works.
Experiment 1: After a while - tried to send. The device is not responding.
Experiment 2: Tried to use Telegram and WhatsApp. Message passes immediately on both.
Experiment 3: Tried the my test app again. Not working.
Experiment 4: Tried to downgrade from FCM to GCM and all the way to C2DM. Same thing, not working.
Any ideas?
To make it clear:
The token is okay. In most cases it works. It just falls asleep after a while.
It's a Lollipop device so no Power Saving exempts here or battery saving.
I use priority:high on the payload.
It is no server issue because I use FCM composer and it's just the same.
Waking the device does not necessarily fix it. It just begins to receive notifications minutes later and then all ok.
Other apps such as WhatsApp work without problem whatsoever, always.
I tried C2DM, GCM, FCM. I am using a printout on the C2DM receiver. They all behave the same.
I log everything. Every event, broadcast I get. I don't get push when I should.
Possible clue: some of my customers are using VMWare AirWatch. anybody know about any issues related to AirWatch and Push?
This is not a complete answer so I can't mark this question "Answered".
I found some alternative push mechanism called Pushy. It's mentioned quite a lot in Stack Overflow.
Pros:
I have made tests on a phone where FCM and GCM failed. Pushy succeeded to deliver all my messages, always.
It can work on devices with no Google Play Services enabled
It is also a workaround for the SERVICE_NOT_AVAILABLE issue.
They have a nice friendly console like in FCM, where you can send test messages.
You get a feedback when the message was delivered to Android devices.
Has topics like in FCM so you can send one message to a group.
Cons:
Money. It costs. Not too much. Last time I checked it was 0.5Cent per month for each active user. It may be a lot but my app is an emergency app so availability is a must in my case.
Does not have retries like FCM, as far as I understood. I may be wrong but it does not handle many things that FCM does. It may not do exponential back-off retries or Notification Messages A-la-Apple. I personally hate FCM behaviour on that so I am fine with this.
I am developing an Android app whose main use is to be notified instantly of certain events.
I have a Huawei phone.
The app works well with FCM
I receive notifications in foreground and background, from FCM console and also from my server (PHP code)
The problem is:
I put my phone in ultra power saving mode.
After that I send a notification. FCM return success operation.
Finally I change my phone back to normal mode
I Never receive the notification. Not even if I open my app.
I already check my app in "Protected Apps"
I want to know how to fix this issue. It's an Android bug? It is only a problem of this device? I mean... I do not think my code is wrong... the problem is how the OS manage FCM, google play services or whatever... there is a solution? OR an alternative cloud message service that works well? Other apps like Whatsapp doesn't have this problem.
Thanks in advance
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
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 am creating a app in android 4.0.3 i.e ICS version, which connects to the server when client gets login into the app.I am trying to get status of an client when he gets online or offline through server & seen onto the app screen.I am unable to proceed. Can anyone say me:
Is it possible to get the status of an user through server?
1-- How to proceed for first step...?
2-- How should I get a response from the server that the client is connected & viewed to other client example - when we login into skype our status shows available with green radio button, In same way how can I get it.?
It ll be very help full, If anybody guide me.
Many Thanks..
I'm assuming you're trying to develop a chat app ?
If this is the case, try using an XMPP library. XMPP is widely used for chat apps, including Facebook chat (and Google talk I think) and there are plenty of open source libraries available.
Otherwise, if you only want real-time notifications as a part of a bigger picture, try using push notifications. Google supports Cloud to Device Messaging (C2DM) for android. It allows to have push notifications to a specific device without you having to deal with persistent connections, battery and CPU use .etc.
C2DM approach comes down to this. When a client connects to your server, get a list of his friends and their 'C2DM IDs' and fire a C2DM push to their devices. This push is delivered to your app, and you can respond to it by firing a notification, or update UI .etc. (Your app doesn't necessarily have to be running. Push notification is delivered via a specific broadcast, and your app can register a receiver for it to wake up.)
Keep in mind that there is a quota for C2DM messages per device, per app and also a limit for the payload per message. So you're not supposed to send massive files via this. Just a notification to your app, so it can call your server and get an updated list, instead of polling.
You can get more info on C2DM and code samples here. https://developers.google.com/android/c2dm/
Hope this helps.
You may have moved on, but I'm posting for anyone who would run into this one in the future.
Firebase is a good solution to use in this scenario, if the app is always running when you want communication to happen. (It will not wake up your app as C2DM/CDM does, unless you have a service running all the time and still wouldn't wake up if the device is asleep... AFAIK)
It may be useful for some scenarios, but may be not for a chat app as you want the device to wake up when a message arrives.
Note that they have limitations on the free subscription though.