Java library + app to send push messages to android device - java

I am doing a lot of long lasting computation stuff in java and want to stay informed.
Is there any standard method ( library etc. ) to send push notifications from a desktop java program to my Android device?
When there is no , could someone provide me with some starting ideas how to write this on my own?

The "3rd-party application server" mentioned in https://developer.android.com/google/gcm/server.html can also be a desktop pc running a simple java program.
You will need to setup some IDs, an app that receives push messages, a way to display the phone registration ID so you can enter it in the desktop app.
But the rest is basically as simple as adding the gcm server jar to a desktop app (I'd use this version here: https://github.com/kurthuwig/gcm/commit/d37f4d1c37ed8deaf1a161ca7b881c1d843f80df ) and then calling 3 methods or so.

Like what zapl suggested I would say GCM is a good choice. Also, all benefits aside, if you're into messaging you can have a go at AMQP, specially the RabbitMQ implementation. You can run the RabbitMQ server on your desktop and push your messages out to all listening devices.

Related

Send message to my Whatsapp from Java Client

I have a Java project and I would like to get notified of certain runtime events by receiving a message in my personal Whatsapp account. I was wondering if this is even possible and if so, how can I accomplish this? Is there an API or Java library that I should be aware of?
Thank you for your help.
WhatsApp Inc. doesn't allow sending messages programmatically for personal accounts. But WhatsApp has started taking requests for business accounts in which they might allow certain programming features like integrating with your own code for sending messages etc.
I had once written a program using selenium to send message via WhatsApp Web. It worked perfectly fine. This was for experimental purpose only.
There are few 3rd-party libraries available but you run the risk of getting your number blocked. WhatsApp tries to detect if you are running such libraries. And if they catch then they will immediately block the mobile number.
Selenium method doesn't have such risk. Because you will be using WhatsApp Web only (via selenium).
For your application, the method suggested by #C-Sway is good enough.
You might want to look at Telegram as an application for this.
https://telegram.org/
AFAIK whatsapp will be tied to a mobile/cell number, which will hinder you from the outset, whilst creating your own private telegram channel to monitor automation on your site is very simple, they encourage bot use for this kind of thing and you'll find guides on how to create them below:
https://core.telegram.org/bots/samples
Additionally Telegram can be installed on any phone and the notifications are very reliable and customisable. Enjoy.

How to implement push notifications on my android device

I have a very basic design of my entire application, where several users with my app on there android devices commits data to the server (I have used REST web services(java) + postgresql as my server) through HTTP post request from the android application. I am successful in achieving this and app runs absolutely fine. Now i want to implement a scenario where any change(CRUD operations) on my db on server should create a notification on my users android device. How should i achieve this with my server design unchanged? I have looked into Google Cloud Messaging, but could figure out the server implementation.
For now i have implemented db triggers on postgresql and able to get control back into java code using Notify/Listen feature of postgresql. From here i need to connect to android device. How can this be achieved. Is Google Cloud Messaging the only way? I have not seen any insert/update statements in there server implementation. Could anyone please guide me on this?
either you can use GCM or implement a Socket at server end and open a socket connection from mobile but this approach may add some additional processing overhead because it will create a daemon thread to listen socket port from mobile device.
You should use native library (NotificationManager etc.), here you can find a great tutorial.
My Advice is for you to use GCM. GCM normally takes a maximum of 4kb, so you could have your own defined "commands". You could use them to determine the requests on both ends, ie on android app and the server end. A php script on the server would help you in this.
I am working on an app where by the android app sends messages to the server via POST and the server forwards the message to the appropriate user via GCM. In my case I have very many things to share so in that case I am using commands, for example if it is a new incoming message I send a GCM to the app with one variable as the command and the rest as the data. On the android app I use the command variable to determine what to do with the data.
Kindly avoid that socket advice, it will have your app drain the battery to sustain the open socket , besides you don't have to re-invent the wheel while Google servers already has it

What is the established way to request data from an android device

I currently have an small application that I have been using to learn java/android programming. Right now I have a setup were the app on one phone sends a request (via sms) to another phone running the same app. The remote phone receives the request and sends back some info. Next I would like to try this from the web. Is there an established "best" way to to this?
I was thinking I would have a web server send requests to the device via google cloud messaging and then have the device return the data directly to the web server. (Not that I really know how to do any of that just yet).
I see that there is a google cloud messaging return path (send messages from the device to the google cloud server, but it seems very new, do I need something like that? The main thing I want is to be able to ask the phone to do something when I want, not have it poll to see if there is a request, or just periodically update some status.
UPDATE:
Thanks to the answers below for confirming to me that I was on the right track.
I now have some basic functionality.
I started out using this gcm android demo code
https://code.google.com/p/gcm/source/browse/#git%2Fgcm-client%2Fsrc%2Fcom%2Fgoogle%2Fandroid%2Fgcm%2Fdemo%2Fapp%253Fstate%253Dclosed
and this ruby gem
https://github.com/spacialdb/gcm/blob/master/README.md
between the above two I was able to send a message to my phone pretty easily.
To get the round trip working, I setup a very simple rails app on heroku.
I included a modified version of the sample code in the gcm gem in a controller and then used
HttpPatch (needed for rails 4) to send a post/patch from my phone to my web app, the controller then echoes the message back to my phone.
I guess it would be nice to get the two way gcm stuff to work, but I am not sure there are any gems that handle that, and I am not qualified to handle a task like that :)
I would say it's the right call: Google Cloud Messaging for Android
From the site Android Developer:
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
In this case you don't want to fetch data from the server but you want to send them.
You can send them in different ways. I would suggest, since you are learning, to try a RESTful solution using one of the implementation of JAX-RS.
As a short and direct answer for beginner : GCM (Google Cloud Messaging) would solve your issue. However, if your app turned out to be something bigger, other more technical and complicated solutions are present too.
see this link.

Sync desktop application with android application

I want to raise an event from my Android application to my desktop application which is in Java. Can I do so? If yes, which API to use? Any examples or code snippets?
Both android and desktop applications are clients. Two clients can talk to each other via server or at least initialize their connection via server that is running on pre-defined location (IP address). So, you need some server that allows to do this.
You can probably use (or abuse) some 3rd party servers for this. For example if your desktop application "knows" the phone number it can send SMS via one of available web services. The android application will catch the SMS and take information from its text. You probably can use Skype installed on your machine or email to send messages among applications too. But better way is to develop your own server that exposes RESTful API and use it for the negotiation.

Send sms from java servlet to cell phone

I want to create an application which send sms from java servlet to mobile device, it's my first time to make like this application.
I found many APIs that supports this feature, actually they confuse me, so I choose one tutorial and follow it,
here's the link of the tutorial http://www.visualgsm.com/tutorial010_send_sms_java.htm
I download VisualGSM Enterprise Server (SMS Gateway) and run it, try to make the steps as mentioned, step 3 in example 2 doesn't work.
I want to know, whether I can make real testing for sending sms? Can I receive an sms on my own cell phone??
what is the best way to send sms? I really confused :(
There's 2 ways to do this: via modem or via API service.
There are various services which provide a gateway to the carriers as a service. They are called aggregators. A few industrial grade ones are mobile messenger and ericsson other consumer grade aggregators are http://www.twilio.com/sms/.

Categories