I'm new to Android and want some advice please.
I need to build two Android applications.
Android application for train travelers
Purpose: Sending a custom message (for assistence) to the railway guard. The railway guard will be identified on the basis of the wagon number that has been sent.
Android application for train guards.
Guard must be able to login and be able to receive (realtime) messages from travelers.
In short, this should be a one-way messaging system.
I'm used to build RESTful web application with databases. I have no idea which technologies i should use in this situation. As far i know i can't use databases such as MySQL, Oracle on Android. I've read that Firebase is an alternative for this but i'm not sure if it's the ideal solution for this kind of application.
I could build a RESTful server and make calls from the application. I guess if i do so the messages won't be received as realtime push notifications.
Any advice please?
RESTful services are hosted on a server and cater to incoming requests with a response.
Remote notifications are handled by a remote server. Under this
scenario, the client application needs to be registered on the server
with a unique key (e.g., a UUID). The server then fires the message
against the unique key to deliver the message to the client
application via an agreed client/server protocol such as HTTP or XMPP
and the client displays the message received. When the push
notification arrives, it can transmit short notifications and
messages, set badges on application icons or play alert sounds to
attract user's attention.[21] Push notifications are usually used by
applications to bring information to users' attention.
Source of above text
You can understand the basics and implement it into your application.
However, it is too much work and you really won't be gaining much.
It is much better to use Firebase and the documentation is quite good.
You need to pay as you go based on how much you are using Firebase.
A place to start:
https://firebase.google.com/docs/cloud-messaging/
Related
I read the documentation for FCM in Firebase website, looked into answers here for related questions and googled. All good, but as a newbie I am not sure what's best approach when it comes in choosing the XMPP server.
Is there anything that would limit one of the servers in the list blow when it comes to connecting to FCM? I have a list of servers here.
Should I choose one of the servers in this list for FCM if I need device to device notifications or is there any other choice. I need it for when a new message arrives in a chat app or similar cases when a ChildAdded or modified and the app is backgrounded or closed?
I cannot find any info on the XMPP servers and if Firebase has any recommendation. I would need all three iOS, Android, and Web app support.
I am doing a prototype that involves messaging between clients.
What I want to do - from MyApp on device1, able to send message to MyApp on device2. Device2 should receive this and show a notification.
I don't have my own application server to push notifications from GCM to GCM clients.Is this possible ? How to do it ?
What I investigated - PubNub, which has a trial license that seems to answer my need to send messages on a channel without needing a server.
This discussion at SO didn't help much.
sending client to client messages without server interaction
Can anyone suggest better ways ?
You basically have to use a server in one way or another. I think Firebase would be perfect for your purposes. It has an Android plugin you can use that will basically alert your app when something changes in the database. Here is the documentation for that feature. Take a look at this example for implementation. Before you can use the plugin, you need to create an account and whatnot (basic one is free). Here are the instructions.
PubNub Realtime Messaging and Push Notifications
(server not required)
With PubNub, you do not need your own server to do the realtime messaging or the mobile push notifications. You likely have your own server for your database (MySQL or similar, traditional RDBMS, a No SQL DB like MongoDB, or a realtime DB sync, like Firebase) to authenticate users and such.
For realtime DB or non-DB type change notifications and signaling (any type of realtime messaging), PubNub makes is super simple to receive messages in realtime with a mobile push notification fallback in one publish action. So the GCM message will be sent along with the realtime message. If the app is actively running, you get it in realtime (< 1/4 on average - typically faster) and the GCM message will be received if the app is not active (background or not started at all).
And PubNub's free plan is not a trial (anymore). It is free (including all add-ons) for as long as you stay within the free plan limits.
See the PubNub Android docs for more details and contact PubNub support if you have any further questions with getting started or getting answers to any questions you have as you progress with your app implementation.
Another possibility is to use the SMS.
Android Send and Recieve Messages
"Send Binary (Data) SMS
We can send binary messages (as opposed to text based messages that we covered earlier) to specific application ports using sendDataMessage(). According to this Stack Exchange thread data sms is one which is sent over 2G/3G as well as GSM. I’ve tested it with mobile data turned off and it works fine charging me the same amount, so not very sure on whether it uses 2G/3G or not, but generally the term data is used in telephony when it’s related to network (tcp/ip). Anyway, SMS’s are generally sent to a specific port on the device (which is probably port 0 [zero]). But using sendDataMessage() we can send SMS’s to some other random port on which our app can listen for incoming SMSs and do something with that. In this case the default messaging app will not store the SMSs in their inbox for both the sender as well as the receiver.
"
I want to implement an instant messagign service analogously to whatsapp.
The messages are delivered, even thoug sender and receiver do not need to be online at the same time.
Is there a framework existing to do so (btw I use a linux server). Is the Google Clouse Service suitable for this? Thank you
Google Cloud Messaging (GCM) is a service that manages small messages to / from android. It does require users to be using google play.
What makes it so cool is they will manage the connections for you. They will queue stuff up for a period of up to four weeks, and after that will send a message telling you that its been more than weeks, and you will need to process a new request to obtain the original messages again.
Its a free service. There are some rate limits, but they seem pretty reasonable. i.e. You can't use it for sending frequent game moves, but its totally fine for normal text messages. As I understand it, GCM is only a server interface. You will have to roll your own XMPP server to store and manage messages. Note: there is a payload limit on GCM messages, I think its 4k or so... not big enough for images. You'd have to manage those via http, and send image names via GCM.
They will also broadcast messages to users (1000 at a time). Did I mention this is a free service?
Something like this link will get you started. The API keys thing and registration #'s is sorta confusing. Once you figure that out, it all works. You can test to your emulator via curl messages to the google server, etc..
Oh, and GCM also keeps track of all your user analytics as well..
You can try openfire. It has offline message and everything. Server can be hosted in linux as well.
There is Layer (Android and iOS support for the moment)
Hey Checkout this easy way to implement chat
Quickblox Api
I am creating a chat application on android using GCM. I'm already able do receive messages from the cloud and to send them manually through a PHP script using cURL. I can simple make an HTTPRequest to this script everytime a user send a message but I would like to know if there's a way to remove this script thus making the android app directly send the message to the cloud. If this is possible I also would like to know if it is the "right" way to do it or if the HTTPRequest is as good as it.
Thanks in advance.
Not really. GCM is not meant to replace your entire infrastructure, just the push channel from your servers to the clients.
That said, there is this concept of Upstream Messaging (from device to Google's servers) but Google's servers then contact your servers (via XMPP of all things) to let you decide what to do next.
You cannot do device-to-device over GCM.
Creating an application that needs to be updated when a user registers on a web app. The simplest solution to me seemed to be to integrate a simple client side polling mechanism. But I've read recently about Google Cloud Messaging which would eliminate the need for polling, instead 'pushing' update events to registered devices.
This seems like an unnecessary addition of another layer of complexity, since the GCM server would act as a mediator to the real server.
Can anyone who has used GCM comment? Is it useful in this simple use case where the application is only updated once, or very infrequently?
If I should do something similar, I would integrate the MQTT protocol in my server and in the mobile app. It is explicitly designed for machine to machine. You can find references in the Mosquitto project web page
GCM would work fine for you, instead of polling the server where there may or may not be any new data wasting battery in the process where GCM you would only send a push when there is new data to get so the battery is not wasted on unnecessary calls to the server.
that being said google does not guarantee that any device gets the push so you need to take that into account