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

Evyatar Saias :

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!

Norbert :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=71236&siteId=1
Recommended