I have developed one Android app for the company which has Push Notification(GCM) as well.
When they send the notification and that time if the device is connected in their wifi network then notification doesn't come but if the device is connected to mobile network (3G/4G) then it receives the notification.
Their system admin might have blocked that web address but nobody knows exactly which address.
So, I just wanted to know which Google API gets called when notification arrives so that I can inform their System Administrator to unblock that web site/web address
Ask your admin to open port number 5228, 5229 & 5230. Hope this solves your problem
For your question, 'What Google API gets called when notification arrives"
To receive messages, use a service that extends GcmListenerService to handle message capture by GcmReceiver.
By overriding the method GcmListenerService.onMessageReceived, you can perform actions based on the received message.
Related
I was wondering how the actual request from Server get routed to the Application if the browser is not running. Also, does the service workers maintain an active connection to the server so that it receives the push notification whenever the server publishes something?
I think for every iOS device, Apple keeps a socket open between that device and the Apple Push Notification Service. Which essentially acts as a router for all notifications across all apps and all devices. So your server can send messages to APNS saying "yo, hit up this guy with this message", and APNS will use the socket it has open with every device to send the notification.
Also check out https://developer.apple.com/notifications/.
And https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server
I know that FCM messages are sent to devices corresponding to FirebaseInstanceId.getInstance().getToken() and on onMessageReceived() the FCM messages are handled according to the need of the User. But if the app is not running and with all the background limitations in Oreo how the OS knows that a message has arrived?
how the OS knows that a message has arrived?
There is a socket connection between the phone and google's FCM server. This connection is shared between all apps on the phone that use FCM.
See here
When you ask FCM to deliver a message to your phone ABC and to the app with id XYZ, google's server will send some data to phone ABC. The FCM component on the phone then finds the app with id XYZ (it has to look up the correct app first because this connection might also receive data for other apps) and deliver the message to id.
This is managed by google so naturally the process doesn't suffer from background restrictions, assuming you set the right priority for your FCM message.
In my android application , i use push notification .I had one if there is no network connection in my android device means .Then push notification works or not in my android device
If the target device is not connected to the internet, then the GCM adds the Notifications to a pipeline to be delivered at a later stage. There are limitation on the pipeline size and the maximum time of un-connectivity, after which GCM aborts the pending GCM messages. But for a general case, this should do the needful.
You need Internet Connection.
GCM clients receive notifications through a socket, which is handled by Google Services to the Internet
Without Internet you will not receive any notification from GCM. Till your connection is not there GCM fill store all notification for you and as soon as you got connected it will release its burrer
I want to implement Push Notification for an App (both iOS and Android) and need clarifications on the following scenarios.
I understand how the Push Notification works in general and the limitations. I did read the docs but that just got me confused and didnt answer all my questions.
How are the following scenarios handled in iOS and Android:
When the device is turned off
When the device is not connected to 3G or Wifi networks
When the device has crashed and need restart
When the App is in foreground
When the App is in the background
When user is currently using the App
When my app is closed (not opened / launched)
When a push notification is user specific and both users share the same device and app. Example: If a husband and wife share same device and use a bank App with Push notification.
Can you send User specific notification if device is shared by multiple users?
When user has installed App on multiple devices
Can you send a notification to all devices registered by a user at once?
Do you store the device type (iOS or Android) with the registrationID in the User table or is there a way to differentiate the type of device by inspecting the token or registrationID?
Can you cancel a previously sent notification which is not read yet and send a new one?
Is it still true that Android Push Notifications does not work on Kindle Fire and will need to implement Amazon Device Messaging
Anything else that I need to think of or plan? I am aware of handling un-registering and feedback service
I would answer some of your questions, specific to android thought. Don't know about iPhone, If its of similar kind or not.
The device receives notification from Google Cloud server as and
when the notification is triggered by the server and it doesn't have
any relation with application state (Running, Closed, Background or
foreground).
If the notification is sent to a device when its not connected to
the internet ( switched off or not connected to the net) , it gets
notification only when it connects to the network. However, if the device
is crashed and restarted after the notification is received, you
won't get the notification again.
Is it user specific?
It depends on the individual servers implementation.
Do we store device type?
Yes we can.
Can we differentiate the IDs of iPhone and android?
Yes, android Device IDs are longer in length than iPhone's.
Can we cancel an already sent notification?
No, it is a one way communication channel as far as I know.
When the device is turned off:
Answer:
IOS/Android Server (Not your Server) will handled when to send the Push Notification. It checks that device is reachable or not. We can define that how many times IOS/Android Server should try to send Push Notification.
When the device is not connected to 3G or Wifi networks
Answer:
Nothing related to 2G/3G/Wi-Fi. Device should be connected to Internet via any network.
When the device has crashed and need restart
Answer:
IOS/Android Server checks that device is reachable or not.
When the App is in foreground
Answer:
Nothing related to app in foreground.
When the App is in the background
Answer:
Nothing related to app in background.
When user is currently using the App
Answer:
Nothing related to app being used currently.
When my app is closed (not opened / launched)
Answer:
Nothing related to app is closed.
When a push notification is user specific and both users share the same device and app. Example: If a husband and wife share same device and use a bank App with Push notification.
Answer:
It depends on how you have implemented on YOUR Server. You will be managing Device Id for each user. So it's upto your implementation logic to send to same device for multiple users.
Can you send User specific notification if device is shared by multiple users?
Answer:
It depends on how you have implemented on YOUR Server. You will be managing Device Id for each user. So it's upto your implementation logic.
When user has installed App on multiple devices
Answer:
It depends on how you have implemented on YOUR Server.
Can you send a notification to all devices registered by a user at once?
Answer:
Yes again as per your implementation logic.
Do you store the device type (iOS or Android) with the registrationID in the User table or is there a way to differentiate the type of device by inspecting the token or registrationID?
Answer:
Yes you need to store the device type, to identify to which Server (IOS/Android), you need to send request for Push Notification.
Can you cancel a previously sent notification which is not read yet and send a new one?
Answer:
No you cannot cancel the request.
Is it still true that Android Push Notifications does not work on Kindle Fire and will need to implement Amazon Device Messaging
Answer:
Need to google it around.
Anything else that I need to think of or plan? I am aware of handling un-registering and feedback service
Answer:
Need to google it around.
1) If a user mobile device is registered with GCM, then will the user mobile get a notification from GCM, if user has changed his SIM?
Or
2) Is it possible to link a SIM with GCM, so no matter how any android phones he upgrades but still recieve the notifications.
GCM definitely does not require a SIM card to be present at all. I just setup up a notifications app on an intl Note 3 with no SIM.
A notification developer can use multiple unique identifiers to link a user to a notification, but the user doesn't normally have any input as to which the developer chooses to use. In many cases you may be registered anonymously as a class, especially if the notifications are not personalized and broadcast to all users of an app.
Keep in mind that GCM notifications are finicky as to when they start arriving after the app is registered. For example, with the Note 3 I just setup, even after rebooting none of the 6 test pushes I sent were received. I also checked/unchecked the app's notification box in application manager (Samsung). I also installed 'Push Notification Fixer' (don't let you dissuade from using this, as it does work to keep notifications prompt after the first).
In this case, it wasn't until I changed Wifi connections that the queue was immediately triggered and flushed to the device. It's annoyingly arbitrary and a pain to debug.
If a user mobile device is registered with GCM, then will the user
mobile get a notification from GCM, if user has changed his SIM?
Yes, user will get GCM Notification. GCM Notification Flow has nothing to do whether there is any SIM in Device or not.
Also if user has not any SIM in device, Device can registered to the Server and will get GCm Notification.
Is it possible to link a SIM with GCM, so no matter how any android
phones he upgrades but still recieve the notifications.
Possible, Your app needs to be installed on the devices and register the device and sim id with your server.
Check TelephonyManager for getting the information you need and then create a database on your server with the relationship between user/sim/whatever(phonenumber?) <-> gcm notification id.
http://developer.android.com/reference/android/telephony/TelephonyManager.html
Basically most apps that send User specific notifications register the user with some identification additional to the device, your sim id can be that identification. you should take into consideration that if a sim is lost then you won't get the same sim id again (it's not your number).