create my own push notification service without fcm , pusher ,
Asked Answered
C

2

24

I want to create a notification system provider that is not based on Google services or similar. In fact, I want to get information about its overall architecture and needed Android sdk functionality.

The most weird point for me is to understand how to send a notification to an Android device.

I mean, how can I identify the Android device on which my application is installed from millions and millions of other Android devices on the Internet?

And how do I send information to him? Should I use sockets for this or similar stuff?

Clarsach answered 14/6, 2018 at 5:16 Comment(6)
Just stop for a moment and think about what you are going to do: You are going to implement a feature, on which a horde of Google developers has been working for a couple of years, and you look like even not sure where to start. I don't say that it's impossible, but you likely are going to spend at least couple of years developing it.Aneurysm
thanks for your answer , maybe I am ready for that and I will accept any help from my friends to catch this target ;)Clarsach
All the best, though from where i see you are trying to boil the ocean.Cohette
ok, then I could suggest some general ideas: Push notifications from FCM are not push in fact. They are pull, as that is the Android device, who connects to FCM servers with some modified socket connection, and reads data once it is available. As for how to know which device to send to - each app instance on the device has it's own unique ID over whole world, which is generated during first FCM client initialization. And you can identify device/app by that ID.Aneurysm
and how do you want to notify your (possibly sleeping) device about a new message? its simply not possible (unless you build your own firmware)Vocable
I want to give some technical info to achieve such a service. The Google Play Service uses some techniques to make server-to-client communications possible. This is difficult to achieve (look for Hole Punching, NAT Traversal,...). Anyway, another requirement is making a live Android service that you can guarantee its running. Google has its own unique service that serves other application requests and Google can guarantee its execution. You have to create your own exclusive service for each application that might be killed by the OS whenever it decides.Fourdimensional
H
10

simple answer: YOU CAN NOT

before everything else i should correct your question, pusher and FCM are not in the same group at all! you can build somthing like pusher or oneSignal or etc but you can not build something like FCM/APNS

you should understand three simple yet important sentences below:

  1. when you want to pull anything from place_1(e.g. api) to place_2(e.g. browser_client) you most have an identifier of the place_1_resource (which commonly is the uniform-resource-locator of api)
  2. when you want to push anything from place_1(e.g. notification_central_server) to place_2(cellphone_client) you most have an identifier of the place_2_resource
  3. you must know the differences between a real server push with server-push-like technologies like long-pulling or ... and you should be aware that what is intended in this concept is a real server push not any kind of pulling with a push jacket!

if you don't have any identifier for a cellphone which you want to send it a notification, your server dont know where to send that notification so we need a resource_identifier_like for cellphones which is actually a device_token_like and you have just one approach to get this device_token_like and that is the FCM/APNS

FCM is like a dns server containing all identifiers of every android device that google supports (almost every android device) and APNS is just the same but for apple devices

note1: even if your app can obtain it's corresponding device device_token_like it can not be used for push notification if its not registered on FCM/APNS

so when you get that device_token_like identifier of your desired clinet_device now you can use different approaches for sending sth to that clinet_device. there are several approaches like SSE, Webpush, HTTP_server_push, Pushlet and etc but none of these approaches supported by mother_companies of these devices, the only approach that is completely supported and standard is the same approach that FCM/APNS official websites suggests

for example an iranian Incorporation named najva uses webpush to send notifications because of USA sanctions but webPush method works good on browsers and android devices but they didn't even apear on an apple devices

finally i should say that i admire your curiosity to less using anything from a benefit_based Inc. like FCM/APNS in your developing but i strongly recommend these articles and books for you cause i think you didn't learn enough:

  1. wikipedia of push technology
  2. story of some guy who tries to make his own push notification service
  3. Push Technology A Complete Guide - 2020 Edition
  4. Data Push Apps with HTML5 SSE
Hydrothermal answered 18/10, 2020 at 0:46 Comment(0)
O
6

Short, direct answer

You can't (At least till you create your own ROM)

TL;DR, Reason why?

Before you build your own push notification server, you first need to know how it works internally in android. Whenever you/your server sends a push notification message to the android client, the SDK processes it and shows you the notification. But when your app is not running (or being killed), your app cannot respond to it since it was not running. In such a case, your notification message is sent to a system service which is known as Google play service. For this even to work, you will first need to bind your app with Google play service and that is what FCM does. FCM SDK registers your app to the operating system service on the first initialization. That FCM service is opened to a port which listened to the incoming message from the server and when it receives the message, it publishes a notification on behalf of your app with a PendingIntent containing the data. Then the PendingIntent is delivered to your app when the user clicks it and then finally your app process the data (or the push message)

So basically, for your server to communicate with the client, It first needs to communicate with the FCM service and for that, FCM gives you a token which identifies the application to register with the internal Google play service.

Simplified furthermore, the workflow is as follows:-

  • Server send push message ---> FCM ---> Google play service,
    • If your app is running, it is directly handled by the client SDK So, Google play service --> Your app
    • If not, then it is delivered by the service itself using PendingIntent So, Google play service --> PendingIntent --->| Publish notification

Totally impossible, Workaround?

There is nothing like impossible because an absolute impossibility doesn't exist. Saying impossible generally means near to impossible. (This is similar to math where also we say tends to infinity because no one has achieved it yet).

To make it work, you need to somehow bind your app to the Google play service and you can't because Google hasn't exposed any direct API to do that. The only possible way is using the FCM ;-) (Bad luck again). So the only possible way is to build your own custom ROM with a custom push service that acts as a client for your Push server and a Server for your Push client (which is your app).

Since the above option tends to impossibility, you have to choose a workaround.

The best among the worst workarounds are:-
  1. To make a malicious SDK. Malicious because it needs to keep the app running in the background with a service that is connected to a WebSocket endpoint of your server. (Harder in new android versions).
  2. Make use of a database where your push notification is saved and your app checks it periodically using AlarmManager.

Hope you have got the point.

Orthopsychiatry answered 13/6, 2022 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.