Android Push Notification from device to other devices - java

I have been trying to learn android programming following Ravi Tamada's tutorials - AndroidHive for weeks now.
I created an app that performs Create, Read, Update and Delete actions (CRUD). Similar to this .
Now, what I want in my app is to have another feature that whenever there is a new data created and/or updated in the database, the app sends notification to other android phones that have the same app.
I've researched and come across Google Cloud Messaging, which AndroidHive also have a tutorial for. The way I see it is that it is only the server that can send notification to devices and GCM cannot do: "Device to another Device" For instance, "Device creates data -> send to database -> GCM sends notifs to other devices". Correct me if I'm wrong.
So I've searched again and found that you can use Smack for Instant Messaging app. Similar to something that I want my app to accomplish. But I'm having trouble understanding and implementing Smack to Java and Android.
So what I want to know is:
1.) Is it possible for GCM to listen to a device to check if the app has change the database and sends a notification to other devices that there is a change in the database?
2.) Do you have any "noob-friendly" article links on how to have a basic understanding and implementation of Smack in Java-Android?
Thank you.

Check out the official tutorial on the Android developers site:
http://developer.android.com/google/gcm/notifications.html#upstream
You can just upstream a message to the Google cloud and it will be sent to other devices in the same notification group.
I'd suggest that you always start with the official tutorials first and then move on to third-party blogs, it's just easier that way.

Related

Bluetooth LE send string data between Android devices via application

I'm completely clueless on how to use BLE. I need to create an application for Android devices that sends a small string from one Android device to the other. I am NOT using any sensor type devices. I only need to send a string from one phone to another phone using a BLE connection. From what I understand, I need to create a custom service and implement a GATT server on a central device and have a peripheral device access it as a client but I'm not even sure if that's what I need for my situation. I have scoured the internet and nothing I have found deals with this topic specifically. I have no idea how to create a GATT server for this purpose and what I need to include in order to create a service. Can someone please explain to me what I need to do or point me towards some resources that are useful for A COMPLETE NOVICE? Thanks.
You are right so far. You need to create two applications on two different Android devices as follows:-
Android App A on Device #1: An app to act as a GATT Server to host your data that you want to send. For that, you will need GATT Server API.
Android App B on Device #2: An app to act as a GATT Client to connect to Device #1 and read the string data from the GATT Server using GATT Client API.
BLE is a relatively complex technology but luckily there are so many resources to help you get started. I recommend that you first understand how BLE technology works and for that I the following links are useful:-
Introduction to BLE Video Series
The Basics of Bluetooth Low Energy
Introduction to BLE GATT
Getting Started with Bluetooth Low Energy
Getting Started with BLE GATT
Once you have a better understanding of the protocol, the following links are useful for understanding Android BLE development (in addition to the video posted in the comment):-
The Ultimate Guide to Android Bluetooth Low Energy
Getting Started with Bluetooth Low Energy in Android
How to use Android BLE to Communicate between Devices (With Examples)
However, before going through any of these, it's always a good idea to get a feel and practical understanding of how the technology works. For that I recommend using the nRF Connect Android app to connect and read data off devices. This way, you'll be able to relate to the new information and hopefully understand the new concepts easier.

FCM - Sending notification to my android device from Java

I whish to create a simple Java project which uses FCM.
I found a lot of tutorials on the web, but unfortunately it is not really clear how it works.
I want to write a simple Java code which sends a push notification message to my phone device (android).
I read through the offical FCM website, but I cannot understand how can I make a real connection between my phone and my Java project?
It needs any device ID or token?
How it works?
Thanks a lot!
To send FCM messages from Java you can use the Firebase Admin SDK. See the documentation on sending messages for full details.
Note: this will only work from a JVM. It is not possible to use the Admin SDK in an Android project.
A little late my answer, a short code to send a notification from android, using: FCM-AndroidToOtherDevice
FirebasePush firebasePush = new FirebasePush("LEGACY_SERVER_KEY");
firebasePush.setNotification(new Notification("title","body"));
firebasePush.sendToTopic("news");

Android: How to setup a connection between two mobile devcies (Wi-Fi or network)

I am developing a game app where I am using Facebook SDK login button to retrieve the friend list. I want to send an invite to challenge their peers on the app. So the app receives a request from someone that they want to be challenged.
I do not want to use the request Dialog that uses facebook notifications. I want my own app to receive the notification and notify the user for incoming challenge.
I did some research and I could use the NSD but unfortunately it only allows you to connect to people on the same network. I want to be able to connect to friends from far away. I heard you can use emails but I have not found any documentation.
If you can point me to the right direction I really appreciate it.
ok i suggest the below approach for what you are trying to achieve, use facebook sdk to get the user friend data, there will be an id and name in the response. you can use this facebook id to give people a unique id in your system. when people are wanting to challenge their friends you use their id from facebook friendlist and lookup in your system if these friends have registered/ install your application. if so you send a notification to them if not may be you suggest them to send them a email or sms with a uri to ask them to install the application. Try the Graph API Explorer to play around with the data you can get from the Graph API.

Android - How to notify the user one row is updated in data base

We developed a Hotel Menu Order project in android. Now We have created the project successfully. We are using java, Jax-rs for web service, Mysql for database and Rest for communication.
Now we want to add some more features in our app. When the customer conforms their order that order should show to kitchen and admin. When we google for some example we found one way. That is Google Cloud Messaging. But this is online sevice. We can not use this service.
Because we are using in offline services. We use one centralized server in the hotel and all the devices will connect with WiFi. There is no internet connection.
In this case how to notify the user a row is updated in Database. Please let us know how to achieve this.
Via SMS, what you can do is that you can send the sms to the devices using thrid party services like twilio, on client side i.e. device end you can get the sms broadcast validate the number and the sms content, read the content and update the application DB and the UI accordingly.
Or if one device has internet then what you can do is send GCM notification to that device, and from that device you can update the other devices through wifi direct. But wifi direct has some limitation, I think using SMS is a better option.
u can use Google Cloud Messenger services, by which google provide free message service to your client. http://hmkcode.com/android-google-cloud-messaging-tutorial/ this example will help u to understand better.

How to implement Beluga or WhatsApp like messaging system in Android 2.1

I am trying to develop a message app within my android app. The message will be like whatsapp and beluga. I googled it and found C2DM Android 2.2 can send the push notifications to the device. However, this is not available on Android 2.1. Anyone knows how whatsapp send the notifications for 2.1 devices?
For Android: Whatsapp is build upon C2DM and when the app opens it opens an XMPP connection to their service to deliver the messages instantly. They also might use MQTT as a protocol to minimize battery usage. That's basically it.
Edit: I learned more, Facebook uses MQTT in their messaging app. Whatsapp is build upon XMPP with their own extensions. Their server side runs on top of ejabbard (XMPP implementation in erlang). http://www.ejabberd.im/
On pre 2.1 devices WhatsApp probably keeps a connection open to their XMPP servers in the background but this is not really good for battery life.
C2DM is replaced by GCM (google cloud messaging) now . you can use it for delivering the notifications to your app . For the exchange of message one should rely on protocols like xmpp (whatsapp), mqtt(facebook messenger), mtproto (telegram) etc.
if you are looking to familiarize yourself with GCM . try out this tutorial by appsrox - Create an Instant Messaging app using Google Cloud Messaging (GCM)
they are using GCM for the message delivery as well. it won't suit for production, but its an excellent resource for people who want to develop an instant messaging android app .
I don't know what exact technology is used in whatsapp. However, if i am to implement notifications where there is no support for push notifications from the OS, i can do two things:
Poll a remote server every X seconds and check for new notifications (this is the more expensive choice).
Run a background service, maintain a connection with a remote server, which will pump me any notifications that are to be received (sort of my like my own push notification implementation).

Categories

Resources