Cordova App restarting after inactivity - javascript

Good morning
I'm developing a cordova application for my internship.
The application tracks the position of the user and does some logic with it to generate data the user needs.
This all works fine but the application needs to run as long as the user has a button on the main screen enabled
but right now when the application is running and you enabled the button which makes the application track the data. Then when the screen is turned off the application gets turned off and doesnt track the users position anymore.
I presume the application is suspended but then when you open the application again it is like you opened the application for the first time. (button turned off)
Is there a way to keep the application active? i know in native android you can write a service which does this but i need something that works with cordova
thanks in advance for the help
regards
bavo

Related

How to find whether the user is watching our website or not(it should work when switching applications also)?

I am creating a chat application, where I need to send notifications when the user is not watching my website or working in another application.
Now, most of the use cases can be handled using the page visibility API. But there is a particular use case when the user is switching the application from browser to any other application(ex: Outlook), I want to send a notification at that time.
But the issue here is page visibility API does not provide anything on switching applications. That is if the browser active tab has my website and the user switches the application from browser to any other application, it still thinks the user is looking at my website which is wrong because the user is in anther application right now.
I have done R&D on this and I see it is impossible because browsers can't detect these kinds of changes due to security reasons.
But when I checked with Whatsapp web there, javascript is able to find weather user opened the current application or not and based on that they are sending notifications.
So, How can I implement same feature that Whatsapp guys implemented? Is there any web API I am missing here. Are any hacks available to implement this kind feature?
Thanks in advance.

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.)

How to detect that User has added webapp to the homescreen on mobile device?

I am working on a webapp. I want to count the number of Users that added my webapp to home screen.
suppose my website is.
http://www.example.com
I have added meta tags that allow Mobile users to add it to home screen. I want a count of users that downloaded my webapp. If User has downloaded even if he has not opened that then also I should get notification that User has added it to home screen.
So I need any event that should work when an Webapp is added to home screen.
My webapp is in HTML5
First of all, officially it's not possible, as per the official FAQ:
How can I detect if the app is running as an installed app?
You can’t, directly.
which is again re-iterated
Best practices
Do not prompt the user to add your app to the homescreen. There is no way to detect if the app is running installed or not.
Source: https://developer.chrome.com/multidevice/android/installtohomescreen
You could do some manual checking of the screen sizes though on page load, as chrome can't go fullscreen by hand, but do not rely on this (though for statistical purposes it might be interesting).
Another clarification which might be useful, the application is not downloaded when it's added to the homescreen. All that happens is that a 'link' will be created to chrome with certain parameters. By design little information is disclosed to developers regarding this process to prevent companies from forcing users to 'install' webapps before they would function.
As of 2018, according to https://developers.google.com/web/fundamentals/app-install-banners/:
To determine if the app was successfully added to the user's home screen after they accepted the prompt, you can listen for the appinstalled event.
window.addEventListener('appinstalled', (evt) => {
app.logEvent('a2hs', 'installed');
});

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.

Background Application on Smart TV

I have an application on Samsung Smart TV. I'm fetching data from web service and display this data in my application.
I'm fetching the data periodically and updating the application accordingly.
I want to run this operation as a background process, so it'll download the data and if there is an update, I warn the user when s/he watching TV.
The other thing I want is to start application on TV launch, is it possible?
Only 'ticker' type application can run in background. It is not supported in Europe and will not pass certification for Samsung Apps store.
Samsung Smart TV suppots push-notifications (samsungdforum.com/Guide/art00080/index.html).
It will allow you to show popup-message on screen with ability to launch your application.
You cannot auto-start application on TV launch.
The only way is to use custom firmware like SamyGo (http://www.samygo.tv/)
About the "background process"... as far as we assume that JavaScript's setTimeout or setInterval can be used to execute application's "internal" background process, there is no problem - Just DO it! :)
But if you were thinking about system's background process - for ex. crontab of device - it's impossible.
for your second doubt
Auto launch of the application is supported in ticker applications only and there is property in config file of the ticker widget :
"<ticker itemtype="boolean">y</ticker>"
if u mark it as y(as above) than you can set up auto launch of the app from
Menu->smart Hub->Apps settings->auto ticker. in 2014 Samsung Smart TV models.
Since Tv has limited memory I wont recommend background process like setInterval or setTimout. You may have refresh button for the same.
And They must have some js api for controlling internal method of tv application (not sure). Anyway if you really want to use interval/timeout dont forget to clear it.
As it shown here, WebSocket is supported by Samsung Smart TV. Your server application can trigger TV application when an update is appear. It is more efficient way than polling server with ajax for your case.
(Edit) I wrote a sample application to demonstrate:
https://github.com/aksakalli/socket.io-hello-world
(Edit 2) I see that your problem is about platform limits. My answer is just about approaches that can be applied then I have very limited experience on Samsung Smart TV.

Categories

Resources