Android BroadcastReceiver vs WakefulBroadcastReceiver vs JobScheduler - broadcastreceiver

I am in the process of moving a hybrid Cordova Android app with its own custom plugin from API 19 to 23. The plugin sets up broadcast receivers for the following
'AlarmManager.setInexactRepeating' to execute actions on a ca 30 minute basis
LocationServices.fusedLocationAPI to watch for geolocation changes when the app is backgrounded
A broadcast receiver to catch push messages captured via Pushy.me.
I find myself slightly lost with the various changes with the different Android APIs. My understanding is that replacing my current broadcast receivers with wakeful versions will work but will only be a stopgap measure since such receivers are deprecated in API 26+. Just how I can use JobScheduler to watch for geolocation changes and push message broadcasts is far from clear to me. My searches on Google and SO have not yielded anything that I can readily borrow and implement.

Related

Incoming call notification

We are developing an app with angular/ionic in which we use capacitor jitsi plugin for video calls. What we are now trying to do is to receive notifications (via firebase) like in whatsapp with the incoming call screen and two buttons to accept and decline. Any idea on how to do that?
Thanks
If you got the choice to change the notification service, instead or directly using firebase, you could use Onesignal which extends firebase and they already have a service named VOIP notifications which should kinda do your needs and here is the link:
https://documentation.onesignal.com/docs/voip-notifications
In case your are restricted with firebase or need to know how this could be done, bellow will be the way to achieve it..
As for android:
First as logic part, you need to add some code in the native layer since hybrid apps usually can't interact from JavaScript side to native side in case app was not launched, so in order to wake the application on a specific event like notification received or any other actions that phone system can hold..
Second, as technical part, you need to add broadcast receivers and the receivers role stand to interact as native code with system. example in the link below:
https://www.digitalocean.com/community/tutorials/android-broadcastreceiver-example-tutorial
also another video about foreground and background broadcast receiver service in the link below:
https://www.youtube.com/watch?v=rlzfcqDlovg
video code output in git:
https://github.com/borntocoderepos/callrecorder
in the Youtube video example, the user is launching a toast message on phone call if app was opened or closed (background or foreground) so you can launch your app with intent with passing data and capture the data on app start as Deep Links as capacitor (https://capacitorjs.com/docs/guides/deep-links) or Cordova (https://ionicframework.com/docs/native/deeplinks)..
And instead of listening to network or phone calls, you can listen to Notifications and for sure you need to do searches about your topic and or the notification service that you'll choose.
Now for the video and the tutorial not sure of the quality of code so make sure to do more researches about the way its done from different places (could be outdated code or bad code quality or even not complete service and will discuss about this point below).
In android there is policy about using background and foreground services so once you start a service you need to end it after your done so make sure after you receive the notification and launch your app to stop the listening since it would cost power usage and perhaps could be stopped by Playstore as harmful app.
Now considering IOS it should be the same concept so make searches about this topic, but for IOS, the listeners policy as I remember , the receivers should not be waked up for more than 15 mins, so also keep this in mind and make sure you stop the receivers directly after launching your Hybrid app.
Broadcast equivalent receiver for IOS:
http://www.andrewcbancroft.com/2014/10/08/fundamentals-of-nsnotificationcenter-in-swift/

How to make periodic background fetches in Flutter iOS and Android App?

I am developing an app that should fetch an API periodically (every 15 or 30 minutes). I am using Flutter for the frontend development. The app should be available for both Android and iOS devices.
The background task includes a call to the backend. In the backend, a worker is determining certain data (this can take up to one minute) and sending it then back to the frontend. The task has to be (at least partially) initiated by the frontend, as an decryption key is passed to the backend.
I had the idea to use Firebase Cloud Messaging to push the requested data to the devices. Unfortunately, it seems to be necessary to have the Apple Development Program enrolled to use it. As the app is an university project, and I'm not even sure, if the FCM approach is the best one, I don't want to pay the 99€ for the enrollment.
Beside the FCM approach, I found some flutter packages like "background_fetch", to pull the data instead of pushing it, which wouldn't be a problem for me. But all packages I found have the problem, that they work differently on iOS and Android, and are also not very reliable in terms of background task management by the respective operating systems.
Is there any "simple" solution for this problem, like a flutter package allowing me to schedule periodic background tasks on both iOS and Android, which is mostly reliable in that the time periode is respected at least roughly and the background task is not killed while waiting for the response? Or will I have to implement an own server-side Push-Service to avoid the costs for the Apple Developer Program?
Thank you in advance!

Firebase Messaging in flutter sendMessage()

I am a flutter programmer and I use in my projects when it comes to pushing notifications Firebase cloud messaging using node.js
I just discovered that there is a method called sendMessage in the firebase_Messaging package in flutter but I looked every where for documentation and I tried everything to find out how it works but got nothing.
That's all what the package offers as information:
so if anyone used it before or can help me to understand it I would really appreciate it <3
Unfortunately this method does not do what you might think it does: it is not for sending messages from one device directly to another device through FCM, but rather an alternative protocol that is infrequently used these days (afaik).
The FlutterFire documentation describes the sendMessage method as:
Send a new RemoteMessage to the FCM server. Android only.
Unfortunately that is missing a few crucial details, so I recommend also checking out the Android documentation on the Firebase site, where this is covered under sending upstream messages, which starts with:
If your app server implements the XMPP Connection Server protocol, it can receive upstream messages from a user's device to the cloud.
Still a bit vague, but keep reading it also mentions:
Receive XMPP messages on the app server
When FCM receives an upstream messaging call from a client app, it generates the necessary XMPP stanza for sending the upstream message. FCM adds the category and from fields, and then sends a stanza like the following to the app server:
The key here is the mention of an app server. As many places explain: there is no way to directly send messages from one device to another, as doing so would allow any user to send any message they want to any other user, which is a security risk.
The sendMessage method you found allows you to send a message to the FCM infrastructure, which then forwards it to your app server. It isn't much used anymore these days, as tools like Cloud Functions offer (at least equivalent and probably better) scalability with better flexibility.

Flutter own push notifications (store agnostic)

I was wondering, given that Flutter is multi platform and each store requires its own procedure for the final step of setting up Push notifications, would it be worthwhile to implement a full "flutter proprietary push notification system" something that would ignore completely the Android/iOS and other stores implementation?
The main service that the store provides is to "find" the device in the final step of the push, this could be replaced with:
a subscribe / ack of this flutter layer to a server (whenever the app declares that it wants to use it), that will send the message when required (with a messaging queue?)
an always on instance on the phone to actually receive the push (this is probably the most critical part)
UPDATE: I am realising that this necessity will probably be covered by some sort of third party provider, such as what Crashlytics has done with error and crash reports.
Operating system push notification services (OSPNS) are provided by the Android and iOS and other platforms. If you want your messages to be shown as notifications on the notification tray/status bar you have to configure it as required by that platform and there is no other option for this. If you want to use only one push service than Huawei Push Kit might be the one to choose since it can send push notifications to all platforms Android, iOS, Huawei devices and also Web.
This is almost impossible.
Because on the basis of Android, there is a part handled by the OS in the case of push, so even if the app does not reside in memory, it can be processed. If you're going to create a Flutter-only Push system, the Flutter app should always be running as a background service (iOS is a different issue).
If you only want to be able to use push while the Flutter app is running, that might be the way to go. However, it will be difficult after the app is closed.
url link : https://developer.android.com/reference/android/app/NotificationManager

How to develop MvvmCross app with SignalR Chat Technology?

I have a simple app in Android, that uses some features like Services and Broadcast Receivers. It is a simple project, that uses SignalR to make a chat. A basic chat, where the service has the signalR connection and staying listening for any new messages or contact's status's updates.
Then, I have some broadcast receivers:
to start the service,
when receive a new message to add in the chatList
when receive a new contact online to update the contactList.
So it connects to a server that uses SignalR implementation, and do all the server job that is expected from a chatWebServer.
So, I'd like to re-write this app, using MvvmCross, so i could have a WindowsPhone, iOS and Android versions. I know the broadcast receiver could be changed for the Messages Services in MvvmCross, but the Android Services/ iOS Long Tasks/ WindowsBackgroundsTasks would be implemented as what in MvvmCross? Would be possible to have it implementation in Core project, so I can reuse it in all platforms? Can anyone help how would be it archtiecture?
Thanks in regard,
Gabriel Bastos
You will still need to rely on what the platform has available for you. So on Android you would still need to have a BroadcastReceiver or at least a Service which has the SignalR connection, otherwise it will not survive if the application is closed.
iOS and Windows is a bit of a different story, there you are not allowed to have stuff running in the background. So here you would probably need to use push notifications to notify of new messages. Although on Windows Phone you can have Scheduled Tasks or also called Background Agents here I think you can do something every 60 seconds at most.
On iOS you are out of luck you simply can't do stuff in the background unless you are using the built in Location Services or something like that.
MvvmCross does not do anything magically, nor does it allow to create a service which does something the platform does not provide.