Pushing or Pulling notifications - java

We want to implement a back end server [Java EE] for mobile application that sends notification to mobile on some events, I'm asking about the best/simplest approach whether Pushing or Pulling notifications, here you are my ideas/questions
1- The requirement is to send instantly the notifications to the mobile as long as the application is running no need to send if it's not running
2- I read that to push notifications to IOS or Android, I will need to connect to apple/google notifications servers, I felt that this is complicated especially that it requires low level socket programming, but based on number 1 and the project has limited time and budget, do we really need pushing ? and is it really complex
3- I read that pulling date may drain battery and consume data, but what if implementing a simple job on the mobile that runs only 3 or 4 times a day, invoking a simple web service on back end server asking for the notifications
P.S will be much appreciated if you can provide some tutorials for similar cases :)

1) If you're application is already running, is it connecting to the same location anyways? If so you might as well pull for the notifications at that point. However, if the app isn't actively connecting, i would attempt to avoid pulling.
2) Interacting with Notification servers on google and apple site directly, can indeed be a cumbersome task. However there are companies that have made this much easier for you. The advantage of using companies like urbanairship, xtify and mblox will get you started with sending push messages in minutes. (for an example take a look at http://developer.mblox.com/docs/ in the tutorial section).
3) depending on the data you try to present, end users now a days are used to instant data. I can't imagine a service whereby pulling 3 to 4 times a day is sufficient, however if your use case is truly limited to 4 times a day, and there is no other activity going on in the background process you create for this, you might as well have the background process running. But do think this through carefully... If at any point in time you want to increase the number of times a day you read, you might soon get to the point where a rewrite is needed to ensure end user satisfaction.

Related

Firebase real-time database latency

I am using firebase real-time database for my app. It's great but I am facing a delay of some seconds during writing data from the app to firebase for the very first time. Means every time when I starts the app it takes a time of 2 seconds to send data to firebase. And after that it works fine with great speed. I know this isn't a big delay by any aspects but in my case I seriously needed the data transfer and fetching instantly. Is there any way to reduce this delay ? Thanks in advance.
The first time you access the Firebase Realtime Database from your code, the SDK has to establish a connection to the server. This involves multiple steps, which are only needed upon establishing the first connection. This explains why the first connection may take some time, and indeed it is not uncommon for it to take one of more seconds.
There is nothing you can do in code to improve the actual connection speed. That is up your bandwidth and latency (which I assume you're not interested in changing), and the SDK and server (which you can't change).
All you can do is start connecting as early as possible in your app's lifecycle, instead of waiting with it until you need to firs read/write data. For example, consider adding a listener to .info/connected when your app first starts.
True,
hi vj Shandilya to my knowledge, the initial connection ought to take a tad longer than expected as this was the case while my team and I were working on an IoT based project linked with firebase and Android-Java.
Maybe you can add, a custom (not intense) progress animation to cover up for the 2 sec.

Is this supposed to take this long?

I am using LocationManager's requestLocationUpdates() to get the user's coordinates on opening the app, and it takes longer to get the coordinates than in other apps.
Getting location takes a while, however while my app is still loading and waiting for location (I am using LocationManager's requestLocationUpdates()) for much longer than other apps.
Here is a screenshot of my notification panel when I launch my application:
Notice it says Finding Location... when I open my app, because my app calls LocationManager's requestLocationUpdates() as soon as the app is opened.
Here's the meat of the question:
Even while this notification is in my presence, if I navigate to an app like google maps, it is able to pinpoint my exact location in a matter of seconds. Is that because google maps uses getLastLocation?
How come other apps are able to fetch location much faster than mine?
So there are two ways of getting location- fine (gps) and coarse (network). Google Play Services provides a 3rd method, but it uses a combo of those two. GPS takes a long time- it literally has to talk to 7 out of 2 dozen or so satellites to get a location for the first time. Network is fast, it just needs 1 network request (or less if data is cached).
A lot of apps will use both simultaneously, using the network to get a fast answer, and then improving to GPS when it gets that data. I know maps does this. This will get you a fast inaccurate answer, and allow you to improve the accuracy later.
You can use getLastKnownLoacation to go even quicker, but you have to be able to deal with it returning null. Generally network is fast enough.

How to create an app to consume real time notifications

I want to create an app to consume real time data from an API. This API give me information about different temperatures. When a certain temperature is exceeded my app need to notify the event to the user.
This app need to run in Android and a web browser. So, my problem is the architecture... My app need to be a websocket or a REST API?
Any help is appreciated!!
You need a notification service, and google has something like that for us...
how does this works??
Take a look at the image below,
you need to register your android app in the google service, and your web interface will need an id, so everytime you want to push something to the android, your web interface instead will push it to the google server with the Id of the app, then google (no matter how) will localize your app, and even if its not running, they will get the notification,
behind the scenes there is a couple of thing that you must do, bu nothing like launching rockets from the NASA.
I will suggest to take a look to some tutorials
in order to start with the registration of your app, get the api key etc etc..
In addition to what #Xoce showed, Amazon has the SNS service which will push notifications to you. Or, if you application is a web based application inside of a native (i.e. Cordova), I've used PubNub for JavaScript based events.
A word of caution though - you'll need to define "real time" for your application. There will be a slight latency between the event and what your application sees no matter what stack you choose. When I think real time I think in terms of microseconds of delay. You may have seconds of delay. If this is a "hey, your house temperature is above a threshold" type of application then that is fine. If this is "hey, your nuclear reactor temperature is above a threshold" then this may not be the way to go.

Video Streaming from phone to internet visitors, with a few seconds delay & review

I need to set up a web-based streaming video of an event.
The unit taking the video would most likely be a smartphone
(or possibly real video-camera somehow tied to a computer)
What I need is
A way to capture the video and compress and transmit over the internet.
(and preferably record in full quality it as well, but that is optional)
Display the video to end users on the website with some seconds of delay.
(plugins or downloads are acceptable, but not optimal)
Display the video to the moderator who gets to see the video live with no added delay.
(in charge of immediately noticing any 'bad things happening')
Provide the moderator the ability to interrupt the transmission to end users.
(obviously, so if anything did go wrong, the end user wouldn't see it)
Before I ask advice on how to write the code, First, Do you think it would be better to
Use an online service for the whole ordeal. (this would only work if the moderator interrupt was available, I didn't find any, but maybe there is one)
Use some pre-built modules or apps that handle these, and the connect them.
Develop these components ourselves, which we are equipped to do using Java.
A combination of 2 and 3. (one example would be, write an app for the Android, a plugin for the Player, and then write our own moderator interrupt, brodcast and delay code server-side.)
Can you help me decide which direction I should take, and the pros or cons of them?

Real time game development

I want to develop a real time game for Android with libgdx. I need to update some variables even dough the game is not running.
For example I want the money to be increased 10 credits per hour (real life hour) so that you can go out of the game and come back an hour later and get that money anyway.
How can I do that?
Thanks
For real time, no need to setup your own server. Just use one of the public time server. Download NtpMessage.java and SntpClient.java from ntp site. Then run SntpClient.java with a ntp port. e.g.
java SntpClient 0.pool.ntp.org
You can use the code of SntpClient class and tweak if you need to.
When user gets out of game (pause state), get the time from ntp and save it. Once the user launches your game, get the time again and compare.
How about these two possible solutions (easy vs. difficult)
The difficult one...
To have a full control, you need to implement the logic in a server and have your application connect to it to get the credits (expensive but excellent solution). Your app will not hold permanent data. Your app will only be used for display, interaction, send/receive data from server.
The easy one...To simply use your app along with phone time. This solution costs much less but your app will be vulnerable against phone time manipulations.

Categories