Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Push Notifications Without using Firebase Cloud Messaging or any other similar service

I am developing an android chat application for learning purposes that uses a server- client architecture. I wrote the server side myself in Java (because I am trying to learn) and the client side is an android app. I am using TCP sockets for communication.

Everything works great when the two clients have their apps open and are connected, but I would like client A to still be able to send a message to client B when client B does not have the app open.

After doing some research I realized that I need to use the android push up notifications that will allow my server to communicate with the client (the android app) even when the app is not opened or running by triggering an intent on the client side. I did some more research and every tutorial that I found is using a third party service as a middle man to achieve this , such as Firebase Cloud Messaging, which defeats my purpose of trying to learn by doing things myself.

Because I am doing this for learning purposes I do not want to use any of these services such as Firebase Cloud Messaging, I would like to trigger the intent myself from the server that I wrote in java without using the middle-man.

The main goal here is to send messages from my server to the android app when the app is closed, without using any third party software such as Firebase Cloud Messaging.

I am unsure of how to achieve this and I would appreciate it if anyone could point me at the right direction. Thanks!

like image 449
Evyatar Saias Avatar asked Sep 03 '18 07:09

Evyatar Saias


2 Answers

In addition to sahand-zehtabchi I want to say, such the service should best use it's own process using android:process in the Manifest so I won't get killed when the main application was terminated and also should implement to be started again after reboot with permission <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> and building a receiver:

<receiver android:name="de.example.BootBroadcastReceiver">  
  <intent-filter>  
    <action android:name="android.intent.action.BOOT_COMPLETED" />  
  </intent-filter>  
</receiver>

But of course such a very sticky background service is not a very nice architecture regarding battery and memory usage of a device. Using any existing Android system service should be preferred if possible.

like image 151
Norbert Avatar answered Sep 28 '22 04:09

Norbert


i think when app is in background, you can start a service and open a socket then start listening for new messages, and when new messages receive,you can handle showing a notification with android sdk notification.

like image 41
Sahand Zehtabchi Avatar answered Sep 28 '22 04:09

Sahand Zehtabchi