what does deviceready event in cordova really do - android

When we creating a watcher in cordova, we need to fire it after the device is ready.
In ionic framework we are using the following code to do that.
$ionicPlatform.ready(function() {
$cordovaPlugin.someFunction().then(success, error);
});
I want to know what this code exactly doing..? What is someFunction() and what is done with .then(success, error);

This is a question which could simply be answered by the existing cordova documentation:
Cordova Documentation - DeviceReady Event
I would also recommend you to read some tutorials or guides on how to start with hybrid app development.
success() will get called, when the device has fired the device ready event.
errorshould be self-explaining.

Related

Ionic local notifications on click not working when the app is closed in ios devices

I’m using local notifications native plugin on my ionic 4
project (latest version), but when I click on notification and my app is closed the click event is not triggered. It works when app is in background or foreground in ios device.
I use local notifications inside a provider and my on click code is inside its constructor but when app is closed it's not working. I’ve tried to write code inside platform ready in app/app.component.ts but this approach does not work. This is my code:
this.platform.ready().then((readySource) => {
this.localNotifications.on('click').subscribe(noti)=> {
alert("ok");
});
});
I have the same issue. I have tried to call it inside platform ready in home.ts constructor. But still no success. I have IOS 12 in my iPad device. This works perfectly when Ionic app is running in background.
But it does not work when App is killed and not opened.
Is it something related to event life-cycle?
https://blog.ionicframework.com/navigating-lifecycle-events/

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

Cordova scheduling task

I am developing an mobile application (platform: Android, iOS) with Cordova.
My application needs ping an URL to fetch data every hours. I want my application still ping the URL when it's closed.
I searched in google and I get some of this plugins:
https://github.com/katzer/cordova-plugin-local-notifications
https://github.com/katzer/cordova-plugin-background-mode
I need a plugin like the second one but also work when the application is closed like scheduled notification like the first one.
Is there any plugin like this for cordova? Or it's impossible to do background task like this with cordova.
Thank you
I had some what the same issue, i needed to pick lat,lng every few minutes and calcuate the distance, but background plugin alone couldnt solve it, as it stops working when the phone goes to sleep .. so I had to make sure, the phone doesn't go to sleep ..
So i used power management plugin together with Background mode plugin.. and it works well..
Background mode Plugin:
https://github.com/katzer/cordova-plugin-background-mode
Power Management Plugin
https://github.com/boltex/cordova-plugin-powermanagement
if( ionic.Platform.isAndroid() ){
cordova.plugins.backgroundMode.enable();
window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
}, function() {
console.log('Failed to set');
});
}

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.

Run application in background Cordova

I'm developing a Cordova application that sends data (registration and image) for external server, it is already working but would like to make it if the user has no internet at registration, the application is running in background waiting for internet connection to send data, how to do this?
Use this plugin
cordova plugin add cordova-plugin-network-information
and cal your code in this callback function
document.addEventListener("online", onOnline, false);
function onOnline() {
// Handle the online event
}
It will automatically run your code when internet will available
other way is to implement background service but this is simple and nice way
https://github.com/apache/cordova-plugin-network-information

Categories

Resources