Android 2.3 and Phonegap, navigator.online does not work - android

I tested navigator.online and it worked until I built the app with PhoneGap, after that, navigator.online always returned true.
Does anybody know how can I un-cache or refresh this value? I need it on "on click" events.

I was also facing this issue while I was developing an application.
What I used is:
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
These events will be fired when the device is disconnected or connected to internet on the fly.
You can store some global variables in the function
function onOnline(){}
and
function onOffline(){}
Than check the values of those global variables and do whatever you want to according to the value.

Related

How can I use cordova-plugin-background mode

I need some assistance to make my App working in background.
I created my first App with Cordova 10, jquerymobile and it works fine excepted in backgound.
The idea is to installed the following plugin cordova-plugin-background-mode, but I get some difficulties to understand how.
I installed the plugin and then I added the following
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
document.getElementById('deviceready').classList.add('deviseIsReady');
cordova.plugins.backgroundMode.enable();
if(Pages.checkConnection() == true)
{
Maps.load();
setInterval(Maps.load, 300000);
}
}
In that way, the mobile is ready, the background mode is actived. I upload my App to my Android but my App stop working.
I wonder, if this is would be a solution
$(window).load(function(){
document.addEventListener("offline", Pages.offLine, false);
document.getElementById("refresh").addEventListener("click", Maps.refresh);
document.getElementById("ffield").addEventListener("change", Maps.field);
document.getElementById("fstations").addEventListener("change", Charts.changeStation);
document.getElementById("threshold").addEventListener("change", Pref.threshold);
document.getElementById("ffieldpref").addEventListener("change", Pref.field);
cordova.plugins.backgroundMode.on('EVENT', backgroundEvent);
});
function backgroundEvent(){
if(cordova.plugins.backgroundMode.isActive()){
cordova.plugins.backgroundMode.moveToBackground();
}
else
{
cordova.plugins.backgroundMode.moveToForeground();
}
}
But I do not know when, it will be actived and if it will work with IOS devise.
Some of you have an experience with Cordova and how to setup the background mode with jQuery Mobile? Any examples?
Many thank for your help and suggestion.
Cheers
You cannot use katzer's cordova-plugin-background-mode with Cordova 10. Works fine on 9.0, but that's as high as it goes. If your Builder program allows you a choice of Cordova versions, pick 9. I have been unable to find an adequate substitute for the plugin that works in 10.
Also in Android, check your config.xml or AndroidManifest.xml and make sure there is FOREGROUND_SERVICE permission. This is absolutely required for background operation.

How to access call log or call event on android and iphone while building cordova apps

I had posted a similar question
How to access sms's or call logs on devices with cordova apps
and based on that we have no permission to access call logs.
How does Truecaller access call logs or call events - on Android it shows who is calling and on iphone the number is detected by the app after call and then it shows who called.
Can we do the same for Cordova apps?
I did find a cordova-calllog-plugin to access device call history. Hope this should help, not tried personally though.
Also looking at the following link, i guess its definitely possible to acheive this in corodva apps

Node.js requests are being sent twice with Android 5.0+

I have a node/express/socket.io app. When i run the app on android 4 and previous, it works just fine. However, with android 5.0+ and greater, every time my app loads and does its initial route (/), it sends the route function twice. The second time it executes, there is nothing in the request body, which is causing the app to error out.
app.post('/', someFunction);
Ive logged this function req.url and notice it is hitting someFunction twice for android 5.0+, but anything previous only hits it once and executes normally.
Does anyone have thoughts on to why this would be caused on new versions of android? and not others? Also to mention, this works just fine with iOS.
The problem was not related to sockets.io. It had to do with how the newer android OS web view handles some JS. In my EJS templates associated with that route, I have a
window.location.reload();
This works great with iOS and older android OS's, but the new versions didn't like it. I was able to switch to:
window.location.href = window.location.href;
And this seems to work just dandy.

execute a function each time, when app started in ionic

I am using ionic framework to build my app, which seems working fine as per my requirement.
Now i close my app and reopen again it maintaining the state which is also fine.
Now my question is
1) Does app.js files run each time when my app is open ?
i tried to add alert in app.js , which works only first time
Is this right or wrong ?
2) I want to run a particular function each time when my app get started. Is there is any way to do this ?
Thanks
There is a very large documentation which gets upgraded every time a new major version of Cordova/Phonegap is released. You can find that documentation here: Cordova Documentation 5.0
It describes an event which is called every time your "device is ready". It is called onDeviceReady. To use this event you need an onDeviceReady-EventListener. The documentation for the EventListeners can be found here: Events in Cordova
You can add that EventListener with this command:
document.addEventListener("deviceready", yourCallbackFunction, false);
Like Zain described in the comments, there is a difference between exiting the application and pausing it, there is also another EventListener which gets called when the user pauses the application. It can be attached to your application with:
document.addEventListener("pause", yourCallbackFunction, false);
So you could create a function which gets called when those two listeners are fired like this:
onDeviceReady
document.addEventListener("deviceready", deviceIsReady, false);
function deviceIsReady() {
alert('Your device is ready!');
}
pause
document.addEventListener("pause", onPause, false);
function onPause() {
alert('Your application is paused');
}
Alternatively, if the alert is not called when the application is paused, you could add the Cordova Plugin Console and call the onPause function with this content:
function onPause() {
console.log('Your application is paused');
}
Please let me know, if this solves your question or if you need further assistance.

How to reset MetaWear Device?

I am currently developing an application that will use Metawear device.
I have noticed that after I connect a device, I can read the live accelerometer values of that device but I want to read/download offline accelerometer values.
For that as per I refer https://gist.github.com/mbientlab/a299fc705f8ac3b64359 , I need to set Trigger.
But when I am setting triggers and if I did not remove that trigger then next time Metawear device unable to detect/scan by my device(Suppose an android mobile).
If device totally discharges and starts again then it resets.
So is there any method to remove that trigger without connecting to the device or reset the device
Thanx in advance
Use the removeAllTriggers method to remove all logging triggers. Line 100 of the aforementioned gist demonstrates trigger removal with the removeTrigger method

Categories

Resources