I've been experimenting with Progressive Web Apps (PWA) and using service workers to create native Notifications on phones (like a Galaxy s7/s8).
All has been working great if the page/PWA is open or in the background/tasks (super slick :D), but one thing I've noticed is that if it is killed via the task manager, the notifications no longer work.
This seems to be the case whether I'm using the web app in the browser or if I add it to home page using the PWA functionality.
Here is a snippet of a simple piece of logic in case it helps:
if (Notification.permission === 'granted') {
navigator.serviceWorker.ready.then(function(serviceWorker) {
serviceWorker.showNotification('You have new notifications!');
});
}
Questions
1) Is this an inherent limitation of PWA's?
2) Is there a workaround (like auto-starting the app, perhaps)?
All has been working great if the page/PWA is open or in the background/tasks (super slick :D), but one thing I've noticed is that if it is killed via the task manager, the notifications no longer work.
I beg to differ. I have created a PWA for a bus app and even if I kill the app, I still receive the notification.
To answer your questions:
iOS is the biggest limitation as of the moment. The idea of having a PWA is to behave and look like an app. Having push notifications and offline caching is one of the things driving a PWA to be successful and not build an app.
There is no such thing as an auto-start. If the user has landed on the page and the SW has installed properly, it is already "listening" in the background.
Related
does anyone have any idea how to make an app that automates and filter rideshare/restaurant apps requests? It's kinda working as an umbrella for more than one app.
for example, the XYZ app will be in the foreground and will monitor both Uber Eats and Postmate in the background and whenever requests are received it will show on the XYZ app screen with its details.
I believe it's not doable on the IOS but its existing on android on an app called Mystor. it uses somehow advisability functions in the phone but I want to understand the logic behind it and know how does it work?
I have developed a hybrid app running on Android, that successfully monitors the users location and displays it to the user as a moving icon on a map. This part of the app is all written in javascript and works inside a webview. The webview also communicates with my remote server to share the user's location with other users of the same app.
Up until Android Nougat this all works even when the app is backgrounded for several days. When the user returns to the app they can see where they have been with timestamps at each point. And all the other app users can see where everyone is, even if they are no actively using the app.
From Android Oreo onwards, I had to move the location tracking to a background service to get it to continue in the background and I have tested this to be still working fine even with the app in the background for a long period. Returning to the app, the user can still see where they have been. However the remote communications to the server, on Android Oreo and later, cease after approximately 2 minutes in the background.
Please could someone explain why this is, and what I could (if anything) do about it?
What is the restriction that I am running into and where is it documented on Android developer? I have set the app as not to be limited in settings/network/data saver and this makes no difference.
Would it make a difference if I replaced the webview XMLHttpRequest with similar code in background service, using volley or something similar?
All help very much appreciated.
Although I have not discovered what restriction I am running foul of, I have found that by moving the http request from the web view to the background service using volley, the server continues to be updated whether or not the application is in the foreground.
Only tested so far on Android 8,9 and 10 in the emulator. Testing soon on a real device
I have developed a react-native app for Android to receive real time food orders (like Uber Eats, Postmates, etc.). The app is running in a Lenovo tablet that is constantly charging. I use a GraphQL subscription to detect new orders and Firebase Cloud Notifications to check the network status of the tablet.
The problem is that right now the system eventually kills the app after some days with no interaction. I would like to know the best approach to prevent the systems kills the app and being able to run it 24/7 in this case scenario.
Thanks!
You should write a service for your app, which starts the app when it gets killed.Never ending service has a good tutorial on how to do this.
I'm having a problem receiving push notifications to an Android Chrome PWA when no Chrome apps are running. I can reproduce this with 3 different public web-push examples. The first question is should a web-push example work the same as a PWA with web-push? That is, should a web push on Android be able to be received and display a notification even if the browser is not running. Docs seem to say yes. Why does the test below not confirm this.
Problem Description
The problem does not affect Firefox. There are other posts that have attributed similar behavior to the payload of the message (data and/or notification) or the battery optimization settings. Altering these variables doesn't seem to improve my situation. Here's a method for reproducing the problem using one of the online examples (Thanks to Carlos for pulling this together..see code here).
Reproduction Steps
Open up Carlos demo on your Android phone. Accept the notification permissions and ensure that you can send yourself a notification.
Open up the same page on another machine. Ensure that you can send your phone a push notification using the "Send to all subscribers immediatelly"[sic] function.
Kill all the Chrome apps on your android device. To be on the safe side, kill all your running apps cause I've found it not obvious what's using chrome and I think this has confused a lot of previous posts/answers.
Repeat step 2 on the second machine. You should not get the notification on Chrome.
Once you're convinced the message is not coming, open any Chrome app. After a few seconds, you should receive the notifications.
Repeat all of the above with Firefox on Android and you will get the notification in step 4.
You can run a similar tests here or here.
There are several bugs related to this issue on Chrome. The problem is resolved in Chrome Dev 74 which is due to be stable on Apr 23, 2019.
I am working on an app with PhoneGap on android where the user will get messages every now and then bringing them to one of the pages on the app. I've looked at a few possibilities but haven't found any simple way to do this. Can I use the built in Notification on the Phonegap API to do this?
I have found a few good ways to do push notifications like thisw: http://www.pushwoosh.com/programming-push-notification/android-push-notification-for-phonegap/ but I want the notification to be coming from the app itself with the time determined by a built in timer.
Thanks!
You can't, not in Phonegap anyway. If the user leaves the app with the Home button, then the code is still running (until it gets killed when memory gets low). But if the user exists with the back key, the app dies. See here: Creating an Android Service with Phonegap? (Have phonegap app run even when closed)