ionic play sound on websocket message in background - android

I am working on an Ionic app, that connects with websocket server and when the app receives new message I want to play audio in a loop till user reacts to it.
All of that works when the app is open. When the app is in the background (or the phone is locked), the sound is not played (either this or the message is not received at all).
Basically, I want similar behaviour to the Meta's Messanger app.
How can I achieve that? I guess I lack some basic mobile app development knowledge, because I do backend on daily basis.
I am developing it for Android.

Related

Web Push notification on android

My team and I are currently working on the implementation on web push notification on android (in pwa and twa context).
The purpose of this dev is to replace sms to notify our users, so we need a certain quality of service.
We implemented a classical solution where the subscription is done through our web interface (angular), the endpoint is sent to our backend and used when some event is triggered to send a notification to the device. All this process is OK. After a subcription, service-workers can be inspected and the push notification endpoint is correctly set.
The http status code returned by the endpoint call (updates.push.services.mozilla.com or fcm.googleapis.com) is 99% of the time 201 but we notice that many notifications are not received by the device. We add some listeners in our service worker to call our backend when the notification is received, clicked or cancelled.
The service works fine on our desktop environment. The notification is received as soon as the browser is launched on both firefox and chrome. It is reliable but this is not our target.
We notice different behaviours among our android testers.
For chrome users, some of them receive all the notifications, some of them lose a few (about 10%), some users lose a lot (about 50%), some of them need the browser to have been launched at least once, and so on.
For firefox users, the service seems to be unusable. It stops working after a couple of days, for no reason : the about:serviceworkers page shows that the endpoint associated with our application is set to null, whereas it has been correctly set just after the suscription.
However, when the notification is received, and clicked, the targetted url is launched but the application or browser stay in background
From that point, we would need several things :
any help or information that could help us having a more consistent behaviour like android or chrome settings requirements or minimal version
a nice way to debug
a way to inspect the running the service workers on an android device (without launching the browser)
more details about the global operating process on android
a way to understand why the successful submitted notification could have not been sent to the device, beyond connectivity problem.
Thanks in advance
Regards
Koj

How can Android playback streaming audio by push notification trigger?

I'm an iOS app developer and not familiar with Android. I'd like to implement the feature that playbacks audio over the internet when the mobile receives a push notification.
I've investigated it for iOS and concluded that it is impossible in iOS because Apple prohibits downloading data over the internet in background from being developed.
I'd like to know if this feature is feasible or not in Android. Could you give me any advises ?
You need to implement PendingIntent to get you notification and start ForgroundService or this or this to play your audio and close it when the user leaves your app or while they are using your app depending your particular needs.

Can my server send data to my iphone / android app proactively?

I am pretty new to the mobile development scene and there is a very basic question to which I cannot seem to find the answer. Here is the scenario.
I have a mobile application. That application is connected to a server that I own. To use the mobile application, users have to login using unique credentials. Now lets say there are certain events on my server, about which I want to notify a particular mobile application user. Can my server proactively send a signal / data to the particular mobile app instance [using sessions data perhaps] so that a notification can be displayed on their screen?
Polling by mobile application towards the server to look for such events is not allowed / feasible.
I can speak to an iOS solution. Android surely has very similar functionality.
There are 2 ways to accomplish this:
Silent push notifications
Background fetch
A silent push notification can be, well uh, pushed to devices without alerting the users. This means that upon reception of the notification, the app can start downloading what it needs from your server. You will need to set up proper backgrounding for this to work properly. Otherwise, the notifications will be queued up and will only take effect when the user opens your app the next time. Start here for push notifications. The payload you send is what controls the notification.
Background fetching is process where your iOS app gets woken up by the operating system (iOS) periodically to allow you to perform a task. This task can be fetch data from a server or anything else you want pretty much. This is probably the best of the 2 solutions given that push notifications are not guaranteed to be received and this puts the onus back onto each device to fetch their own data as opposed to you creating a whole back-end system to perform the push notifications. Start here for background fetches.
You mean something like push notifications? You can read this tutorial (or any other tutorial on google) about how to implement push notifications in your app:
http://www.vogella.com/tutorials/AndroidCloudToDeviceMessaging/article.html
Lookup about push notifications on each of the platforms you're talking about.
Plus look into some live web apps, two that come to mind are meteor.com and nodejs

Can Pusher messages be received on Android/iOS app when the app is closed or phone is turned off

Can Pusher messages be received on Android/iOS app when the app is closed or the phone is turned off?
What i expect to happen...
When phone is on & app is on, it's pretty straight forward from the Pusher docs on how to react to pusher messages sent to the app.
When phone is on & app is closed, the phone should receive a notification that something has been sent to the app.
When phone is turned off, a notification should be received by the phone when it's turned back on to notify that something has been sent to the app.
Are these even possible? If yes, what are some suggestions to lookout for? If no, what can be some workaround?
When an application using Pusher moves into the background on iOS and Android the connection to Pusher will likely stay active for a few minutes. But eventually that connection will be closed. You can't stop that happening within your application (although there may be a "hack" around stating your app is a Voice app when submitting to the Apps store).
Therefore, you should monitor your application moving to the background and put a fallback in place to delivery messages to the phone when it's not connected.
Please see How get pusher events when the iOS app go to the background? for libPusher (the Pusher iOS library).
Here's an extract from the Android Processes & Threads Lifecycle docs on a "Service Process":
A process that is running a service that has been started with the startService() method and does not fall into either of the two higher categories. Although service processes are not directly tied to anything the user sees, they are generally doing things that the user cares about (such as playing music in the background or downloading data on the network), so the system keeps them running unless there's not enough memory to retain them along with all foreground and visible processes.
So, running a Pusher instance in such a thread is a viable option.
However, there will still be occasions where the user goes offline. In that situation your server you can detect if a user is online by querying the Pusher HTTP API or by using WebHooks where your server can be instantly informed if the user has gone offline or come back online.
Using the mechanisms above you can facilitate smart notifications; if the user is online (the app is in the foreground) then send the message to them by Pusher, if they are offline (the app is in the background) then use an alternative mechanism for delivery (native Push Notification, SMS or email).

Xamarin crossplatform, how to reliably send events from server to client

I'm creating video chat (like skype, but for a specific type of companies) apps for Android and iOS using Xamarin. I'm wondering what the best approach is to handle the server to client communication, specifically when a call is coming, how do I fast and reliably contact the receiver ie client phone?
I want to be able to contact my App even if it is closed
I need to know if the message have gone through
It has to be fast, preferably under 1 second
I've read about push notification and they can wake my app, but they are slow and no guarantee they will get through.
I've been looking into SignalR which are fast and reliable, but I can't quite see how to open my app.
Currently I'm thinking about setting a status wether or not the app is open. If it's open I'll use signalR else the caller will be asked if he wants to notify the receiver about the incoming call. Does anyone have better idea?

Categories

Resources