Is it possible to create a client written in Java only, which registers just like an android phone client to receive push notifications?
My goal is: I want to create an integration test on my server which tests if a GCM push notification is really being send. I can not mock the sender of the push notification as that is in another part of the system, developed by other people. Mockito will not help me out here alas.
Rob.
You can't use Android APIs in standard Jave as a lot of required libraries are missing.
Although you could write a AndroidTestCase which registers at the server and waits for a notification to arrive. You just need to wait for x seconds. If the notification did not arrive in the timeout or the registration failes, the test case failed.
Related
I have a Java web application which needs to send manual and automatic notifications to the user.
This notification should go to the user's browser as well as the mobile devices (both iOS & Android).
I found out there is no way to send notifications to mobile devices directly if there is no native application running on the mobile device. So my only option seems to be web push notifications. I went through a few articles and I found it very confusing. I don't know where to start.
Can I send the notifications directly from Java Code? Or do I have to use FCM(Firebse)? If so can I call FCM directly from Java code, such as by calling it using Apache http client libraries?
How does the FCM, client's browser and my application connect?
I also found out that a service worker should run in the background to receive the notifications. How do I integrate it with the Java code?
You can send them directly without using FCM and there are several libraries available, including a Java one.
Unfortunately iOS currently has no support for Web Push. Subscriptions to your service are on a device level rather than by user, so if I sign up on my desktop you cannot send notifications to my mobile unless I sign up again in my mobile browser.
Notifications pushed to Android will be displayed if an instance of the browser is running, in the real world (for me anyway) Chrome always seems to be running in the background somewhere so I get notifications through in pretty much real time. The downside is web push notifications go straight into the notification shade, they do not pop up on screen first.
The rough workflow goes like this:
User visits your page, you load service worker and check for web push
capability, if satisfied you can request permission to send
notifications.
If user grants permission you pass your public key to your service
worker to create a subscription for that user, this returns an
endpoint and two keys which you need to push a notification to them.
Your webpush library runs as a server instance and takes care of all
the encryption and token handling, you configure it however you like
to dispatch messages, usually in response to HTTP POST requests but
it's up to you.
Within your service worker you define an event handler for receipt of
a push message. This is where you create and display the notification
to the user, again how you do this is up to you.
You can pass parameters in the payload of the notification and use them as variables within the notification you display or you can hard code values, you can specify different behaviours depending upon whether the user has your page in focus or not, you can add buttons and set different actions for them, trigger events upon dismissal, customise the vibrate pattern, replace or stack the notifications, access the data in existing notifications etc etc. All this is handled by your service worker, receiving the notification alone does nothing at all.
Your service worker is just a script written in javascript which you link from your page. It is loaded and installed by the browser the first time a user visits and then runs independently when invoked.
Service workers are very powerful. You can also use them to implement complex caching rules, serve content while offline, push data between different browser windows etc. A service worker can spawn more service workers and as they run outside of the main thread of your browser they are ideal for offloading cpu intensive tasks to without delaying the rendering of your page.
Final point to note, your site must be served over SSL to be able to deploy a service worker.
1) It depends a bit on where the Java code that sends a message runs.
If it runs in an Android device, then there is no way to securely send messages from that code. See my answer here for more details: How to send one to one message using Firebase Messaging
If the code runs in an environment you control (such as a server you control, or Cloud Functions), you can call the FCM HTTP end points documented here. The Java Admin SDK doesn't support sending messages yet, although it seems to be under consideration.
I am using mqtt and mosquito broker to build a simple instant chat for an android platform. Now I wanted to implement a condition where any client can check if another client is online.
I know about Last will and testament but I wanted a user to be detected offline only wen the application is inactive or the user is not currently using the app.
I actually dnt need any code, buh wanted an idea as to how to implement this and I would be much grateful.
You can do this without relying on MQTT internals which is much easier in my view. With this approach, you have much more control over what is going on:
The client can periodically send a message within another topic to inform the server of its availability. In case the server does not receive that message after a specified amount of time, it can assumed that it is offline.
The client can also send another message if the user logs out and inform the server a well.
If you insist on using MQTT internal structure, you may find this question useful:
How to Find Connected MQTT Client Details
I am working on an iphone messaging application so using APN Servers to send push notification to offline users (as whatsupp does).
I am using Enhanced Notification Format to connect APNs via an API (com.notnoop.apns 1.0.0.Beta7-SNAPSHOT version).
https://github.com/notnoop/java-apns
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/LegacyFormat.html
In some cases push notification is not delivered to some devices in a short period of time though everything works fine in my server application,
I mean pushnotification byte array is written APNs socket buffer without any problem.
At the same time whatsupp can receive push notification properly after that my client application starts receiving notifications from APNS servers.
I wonder if something is triggered in APNs after waiting 10 minutes and received whatsup notification.
I know that Delivery of notifications is a “best effort”, not guaranteed but when whatsupp can receive notification why my application sometimes cannot receive.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW4
Here is my payload and other parameters:
Expiry:86400
Payload:
{"t":"-13","aps":{"content-available":1,"alert":{"loc-args":["Sender Name John"],"loc-key":"LS_NP"},"sound":"pnsound.aiff","badge":3},"n":"M","m":"NP","j":"905551114444"}
Why I am having this trouble some times? and What I need to check?
Does Apple have an reputation policy in which notification delivered to whatsapp is prioritized?
There is one more notification format (other than both simple and Enhanced)
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html
This format allows us setting priority format, is this format(IMMEDIATELY) get notification delivered 100%?
I am working on sending Push Notifications to an Apple device using Java. For this i am using JavaPNS-2.1.1 library. I have successfully sent push notifications to an apple device. But when i call APNS FeedBack Service it doesnt return anything.
To test the APNS Feedback Service, i deleted the app first from device then sent few notifications to that device. While sending push notifications i called the FeedBack Service every time i sent push notification. But each time it doesnt return anything. The piece of code for FeedBack Service as below,
List<Device> devices = new Vector<Device>();
FeedbackServiceManager feedbackManager = new FeedbackServiceManager();
feedbackManager.setProxy(host,port);
AppleFeedbackServer server = new AppleFeedbackServerBasicImpl(keystore, password, false);
devices.addAll(feedbackManager.getDevices(server));
return devices;
Can anyone help me on where am i getting it wrong? On few Questions here in StackOverflow, i read it works in SandBox environment only, is it true? As i am also working on SandBox here.
What is the exact response does the Feedback Service provides? Will it give me all notifications failed? Or only the device token to which it doesnt delivered the notification? Suppose i sent 3 notifications to only one device, then will it give me all 3 instances of failure or device token of that device with timestamp of last failure?
When should i call the FeedBack Service? Means exactly after how much time i call it when APNS fails to deliver push notifications?
My experience with the sandbox-feedback service is that it only works if you have two different sandbox-push enabled apps on your device. When you uninstall one of them, you'll get something on the feedback service saying the token isn't valid anymore. This was several years ago when I tested it, so I don't know if it still applies.
I am using the Google-GCM service for pushing notifications to a mobile device & building this application in Java EE.
I'm perfectly able to push notifications to the mobile device. And from the client-end (mobile) I'm able to receive input(string).
Henceforth my conceptual question starts: When I'm receiving input from a mobile (let's say: "Hello, Server"), I'm trying to build an automated process on the server-side and in reply it will push a notification (let's say: "Hi client, I'm fine; How are you?") automatically.
I want to grab some idea to push the notification automatically whenever the mobile device is registered. How do I do it?
All realistic implementations of GCM include a stage where an app receives a RegID, and communicates the RegID back to the server, typically via an HTTP service, typically along with some other business specific data. The server would store the RegID, associating it with other data, and later use it to send messages.
Have you implemented automated the delivery of the GCM registration ID to the server yet? If so, in the same piece of code, you might as well push a notification back. If not, do put together some. Server-side implementation would depend on your server's platform, naturally.