Maintaining Android Webview active state - javascript

This is to do with the way Android handles its activity which is giving me some problems.
Ive developed an app with a webview that loads the facebook page and keeps looking for new notifications.
and any new notification beeps the device.
Im using the JavascriptInterface to check the Facebook DOM for the notification count.
Javascript running with setTimeout.
The only problem is, it all works fine until i have the screen on. If i shut the screen for a few minutes and turn it back on I find that a new notification had already appeared on facebook a while ago but my webview missed it and is reactivated only the moment the screen is back on.
Is there a way to make sure that any data the browser page needs to load must be allowed and always kept active by the WebView ?
In short is it possible to run a sort of internet service like navigate to a page every few minutes and run a script on it regardless of my device state ?

Related

Is there a way for Android Chrome to remember Geolocation permission for my page?

I'm working on a web app that requires the user's location to get weather data. It's critical for the purpose of the app, and the location call has to be made basically every time the app is used.
It works fine on Chrome on desktop, but when I try to use my site on Android Chrome it asks for the location permission every time. Is there a way to use the Geolocation API that will remember the permission and not make the user approve it every time?
This is how I'm calling the API, as inline javascript on the page that uses the coordinates.
navigator.geolocation.getCurrentPosition(setCoords);
function setCoords(position) {
// Do stuff to the page
}
It turned out this was happening in a web view when I opened the page from a Facebook message. It remembers the location permission on Android Chrome.

Refresh Page Every time PWA is opened - PWA

I have a PWA where users can redeem stuff. The problem comes when it's PWA on iOS because they don't communicate, so users are able to redeem twice (once in the browser and once on the PWA; if they're sneaky), because PWA doesn't update on what's happening on the browser.
My solution for this would be that every time people are using PWA on iOS and they open the app, it will reload to be updated with the same information the browser one is.
first, I created a function to detect if the user is on iOs and a function detecting if the user is on standalone, to know they're on PWA, so combining these who I created:
if(is_iOS() && isInStandaloneMode()){
window.location.reload(true)
}
But this only created a reload on loop, so I wasn't able to even see the information once.
Is there a way to be able to refresh the page every time the PWA is opened?

How to open iOS App Store from website in a WebView wrapped app?

We have an old iOS app which used WebView to load our website at "m.blablabla.com" (basically, it was wrapping our mobile website).
It's really old. We don't even have build files for that anymore. It has been replaced by a new native app.
But we still have thousands of users who haven't upgraded (even though they can), probably because they turned off auto-update and don't check for updates.
So we added an html/css/javascript message to the mobile website saying "We have a new app! This one will stop being supported soon. [ Update Now ]"
Here I am, genius with no iOS WebView experience (and no environment to test this old app either). I linked the "Update Now" button to our app on the itunes websites, thinking -- it's a WebView, I'm sure the Apple device will figure out it needs to open the app store.
Nope!
Button click does nothing.
I'm actually not sure why it's not working -- not sure if the button click is not registering, or because the device doesn't know what to do with the link.
Any suggestions?
Is there perhaps a specific way to launch app store using JavaScript when this button is clicked...?
Code sample: HTML
Update Now
Code sample: JavaScript
function update () {
window.location = 'https://itunes.apple.com/app/blablabla/id123456789';
}
(Just extracted the relevant code. Implementation is slightly different. On our Android WebView app, it redirects user inside the WebView to the Google Play store app page [using the google play store url]. So the surrounding code is fine, we tested it by mocking the app in Google Chrome. But in the iOS app, just looks like the app doesn't know what to do with the url.)

Detecting re-open of an Android Chrome HTML Webapp

Recent versions of Chrome on Android have added the ability to create full screen Webapps using the 'mobile-web-app-capable' meta tag in much the same way that you can on iOS.
On iOS when you quit a web app and open it again it will always be refreshed; on Chrome it will be up to the operating system resources; and if you re-open the same web app it will often restore the previous app context without reloading the page.
This is causing problems for my Weather Web App as on re-open it often displays old forecast data which can be days out of date.
Is there a way to detect the page re-open so that I can refresh/reload the content?
It seems that the trick is to use timers. Usually, when a webapp is in the background (not a tab background) it's frozen, so it's not executing code. Therefore, if you have a javascript timer that executes every X seconds and on one execution you see that the time passed between executions is far greater then it means that you need to update your data.

Notification from web app (Android)

I'm developing a web app that shows a counter, and when the counter comes down to 0 I want to notify the user(The counter is on a server, so there won't be a problem with reloading the page).
If the user is on a computer, I'm using a popup for the notification, but if the user is on an Android device, I would like the notification to be shown even if the browser isn't open.(I'm using AngularJS if that would be any help)
Is there a way to do this? I rather not build a special Android app.
Thanks.
//G
I'm afraid no, there is no way to do that. When any android application is not active is... not active, frozen. The browser is not a service, so as far as I know it won't process anything while in background. Even it's possible the OS close the browser if it needs more memory than is available.

Categories

Resources