How to use service workers in android WebView? - android

I have created a PWA and I am opening it in the android app's WebView. The PWA opens in WebView, the service worker is also registered when the app is opened in online mode. But, when I open the app in offline mode I am not able to see ServiceWorker js file which was registered earlier. How to persist the ServiceWorker js file?
I went through Android's WebKit, there it was specified that for service worker support in WebView we need to use ServiceWorkerClient and ServiceWorkerController, but it is not clear, that, how exactly to use them with the WebView.

If you are looking for native intervention in service workers you can use the ServiceWorkerController but only on webview pages that have a service worker installed.
Please see this answer for a working example.

Related

How to interval deep link on webview to keep native app session alive?

For example I have native app and I open webview from my app. I need to keep my app alive because If my native app have no activity in 5 mins the session will be expire. So that I have to pass deep link to website So website can keep interval my native app deep link to make native app alive. The Question is How can I write the code to call deep link without reloading or re-direct website page ?
In short, no.
One option would be to (a) refactor the app to more gracefully handle expired sessions (e.g. sign in again) and (b) refactor server to allow new session to restore state of prior session.
Another option would be to change the server implementation so that sessions don’t expire so quickly.
And if you are opening a your web view from within your native app (as opposed to launching a web browser app), your app is actually still running, so there’s nothing to stop you from having some timer that fires off some task periodically to keep it alive from the server’s perspective.
But your answer does not rest within some sly use of deep links.

Progressive web app : Start at android device boot

At work, we are switching from native app to progressive web app.
The last feature that we got before and not with the PWA is that before our application opened automatically at startup of device.
It seems that it not possible (am i wrong ?) with PWA.
We are looking to installing an android native application that could launch PWA at startup. But it seems that we need PWA package name or other to launch application.
Did you know if PWA have a package name or other ?
Or maybe if we speak more generally, did you think if it's possible ?
You need native code here to help start your PWA as your PWA itself cant listen for ACTION_BOOT_COMPLETED, which is needed for you to trigger your app on boot-up.
You can create BroadcastReceiverand once you receive ACTION_BOOT_COMPLETED, use Android Intent Filters of your PWA to deep link from your Native code.
If you are thinking of distributing your PWA to non enterprise environment, where installing your Native code is not controlled and guaranteed, I do not see any other way to call your PWA on boot.

Calling URL and Retry logic in Android application

I have a Java Spring web application running & can be pulled up through an URL. The web application runs in a loop to display different contents. Also I wrote an android app that launches the URL using WebView after Android boot complete so far so good. But I am looking for some ideas on retry logic or restart android app to open the URL if the URL is down in the middle?. The intention is to avoid user intervention, Can somebody shed some light on it?. Thanks.

Run mobile web application in the background as a service

I am working on a HTML5 mobile web application that runs in browser. I want this app to receive server sent push notifications even when the browser/web app is closed. For that reason, I would want my mobile web app to run in the background once visited. I mean I will store some code on mobile maybe cache etc. So the question is that is it possible to run mobile web app as a service on mobile device?
Yes, in iOS, you can let your web application run in background (when it is closed). You have to give some settings to your application. However, in background, the UI threads is suspended, all commands in UI thread will be cached, until you open your application again. So remember to process your services in background threads, else they will be stucked with UI thread.
In Android, you can even create a service (without interface) and let it execute separately from your main application.
For another platform, I don't know the answer.
On iOS you can set a web page to run as a web app. There is even an SO tag for iphone standalone web apps, and the overview explains it nicely.
Here is the equivalent for Android - Add to homescreen

How to have an android phonegap app allways running

I have an Android app (internal for my company, not public) developed using JQM and Phonegap.
The app check each 15 minutes if the company server have some news for the device (1 device = an employee).
But it only works if the device is not in sleep mode.
I would like at least be able to do the same as whatsapp and other apps, send a little message to the notification area and/or shows a little window, sounds a beep...
I can do some of this (as shows a window, sounds a beep) but only if the device is running in visible (not sleep) mode.
Then my question is:
How to have an android phonegap app that is always running, or at least run each x minutes?
I this is not possible... Is possible then create an "mini" real native app only for this purpose, thus "call" to my app each x minutes?
Thanks,
Guillermo, Spain.
link http://www.tipsfromsiliconvalley.com/2013/07/06/create-a-service-on-android-with-phonegap-application/
There is this article on how to create a service on Android with Phonegap which gives some good information on your problem.
It's using a great plugin in order to build a background service with phonegap easily. But you can't use JS though
I didn't find a way to make JS to run in the Background. BUT you can pass parameters from Java to JS and vice versa with the plugin...which is pretty useful. You would still need to rewrite your JS code in Java though.
you could create a service that calls a javascript callback? For example, you could have a service in Java code that when it receives a text message it calls a javascript callback function to execute some JS code? That would be perfect. plugin that seems to create a service and call Js code:
https://github.com/marknutter/GCM-Cordova

Categories

Resources