Environment:
Ejabberd Version : 16.04
Smack-android-4.1.0
I have created an Android chat application with a XMPP server. However due to Google play permission issue I had to narrow down the feature from app which supported receiving incoming message notifications when the app is in the background.
As an alternative I received the following suggestion from GooglePlay Review Team.
Once you’ve removed this permission, you might consider using Firebase
Cloud Messaging (FCM) if your app’s message delivery requires a
temporary exemption from battery optimization. Please set high
priority only if the message is time-critical and requires the user’s
immediate interaction, and be aware that setting your messages to high
priority contributes to more battery drain compared to normal priority
messages
So at the moment users can send messags via the app. But when he close the app, he will be considered as an offline user, and will not receive any notifications from app. When he opens the app again, he will get all the offline messages those were saved the Ejabberd server.
I want to enhance the current app so that even though a user had closed the app he will still receive a notification when some one sends a message to him (Similar to whatsapp)
Is there a module in ejabberd which integrates the server with FCM and handles this?
If we can not achieve this by Ejabberd, is there a 3rd party library to support this?
If not do we have to write an Erlang module from scratch?
I found similar questions in the internet but I could not find any working solution. Since I am not much experienced with Erlang and would be glad to hear your solutions/ideas on this. Thanks in advance.
This can be achieved in Ejabberd with offline_message_hook. This hook is trigger when sending a message to the receiver and receiver in an offline state. So create a custom module using this hook and you can send a push notification to FCM and APNs servers.
Refer this blog -- https://jasonrowe.com/2011/12/30/ejabberd-offline-messages/
Looks like you need to try apply approach below:
Create REST API for store of user tokens with JID's of users
Create custom hook for fetch XML packages.
Integrate into project the epns library(this library can send FCM/APNS)
In custom hook call the spawn function where will be get the user token from DB by JID and creating payload with sending FCM/APNS notification
Related
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?
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:
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)
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
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:
wikipedia of push technology
story of some guy who tries to make his own push notification service
Push Technology A Complete Guide - 2020 Edition
Data Push Apps with HTML5 SSE
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:-
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).
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.
I want to develop a website that will be able to send push notifications to a mobile application that would be able to run on both android and iOS.
For the last couple of years, I am working as a web developer so developing the website is not something that I am worried about, but I have never developed a mobile application before, the mobile app would only receive notifications from the website so the main functionality would be in the website.
Can anyone suggest me what the best approach is and what I have to learn to be able to do this?
Thank you in Regards
I guess, you have 2 options.
You can either use Firebase FCM
https://firebase.google.com/docs/cloud-messaging/
or use a third party which is called OneSignal
https://onesignal.com/.
If you are looking for an easier way then I recommend using OneSignal instead. You just need to define API Key in your build.gradle and initialize OneSignal in onCreate().
The best approach, in my opinion, would be to use firebase (https://firebase.google.com/products/cloud-messaging/). I think it is better because it is a unique framework for both ios and android and you don't need to worry about the user device when sending the message(you could build an interface in your backend code to handle this but why doing something that already exists and it is free).
The flow is something like this:
on the first start the app(either ios or android) must send its firebase ID to your server so that you can store it (simple http request will od it) and set up a listener for the incoming push messages
when you need to send a push message all you need to do is an http request and you can trigger it with js from your website. The request will contain data such as the firebase id of the receiving device(which you have previously stored)
Firebase Cloud Messaging also have some really nice features like upstream messages(push messages from the device to the server, but you need an xmpp server to listen for them) and topics to send the same notification to many users at the same time
I think the best approach would be to create a node server where the website would be running on and then use Firebase Cloud Messaging (FCM) to send notifications
EDIT: FCM supports both Android and iOS
I want to send android push notification to the selected user without using gcm or firebase. The application is already built without firebase. Now I need to integrate push notification too.
Question:
How it's possible without firebase?
Actually I want a feature that, when an admin update the value in the one field in database table of particular user, the that user will get a push notification regarding the update. How it is possible?
The way is to create custom Service https://developer.android.com/reference/android/app/Service.html , which is holding connection via socket or polling some remote server with intervals.
But, I suggest that Firebase service is more advanced and optimized in battery consumption and, particularly, in utilizing the sleep mode. It's not trivial to make a service which will have fast response and CPU consumption. I think that a custom service development will lead to native (C++) coding of networking routines libs.
Also, take into account that Firebase provides own Authentication service with ability to seamless convert your anonymous user to registered. There is a lot of pros of Firebase services. And cons are: your users have to install Google Play Services, if your app will grow - you will pay to Firebase.
Look here Android push notification without Google service
It's possible using VAPID authentication.
Google for VAPID and you will find a very tortuous road that could lead to the answer you are looking for.
another option is Gotify. Gotify is self-hosted open source notification solution that you can use it to send push notification to your android app without need of Firebase.
with help of UnifiedPush you can receive push notifications in your android app.
you can easily host Gotify server on Docker and use it's Api or cli,... to send notifications.
here is a good article about Gotify: https://www.linux-magazine.com/Issues/2020/230/Gotify
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 a push notification, when there is data in server change,delete or added etc The notification is associated with the user. And the Google Cloud Messaging notification is associated for the application running in device. Also there is a lot of over head for developers, when developer are creating the system using google cloud message. Therefore I decide not to use Google Cloud Message.
I know is using XMPP or WebSocket can fulfill my requirement but it is battery inefficient. My question is there a better approach to fulfill my requirement.
You can send the GCM registration Id in the login request to the server and remove it once the user logs out. This way you can send a GCM message to a particular user.
If you want to use a GCM alternative you can try Pushy.me, its also a very good service that uses MQTT protocol and have less headaches as compared to GCM.
Depending on your specific needs, using an alarm and intent service to poll your server every so often - say 24 hours - can work. Then create a local notification if needed. This way no third parties are needed, but you won't have real time notifications.