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
Related
I am developing an app which uses an embedded system connected to through Bluetooth to an embedded device and I want the app to run a function when the device sends a signal.
The issue is that I cannot keep the app open all the time and thus need the app to keep running in the background and keep listening for the signal send by the embedded device so that it can run the function I want.
I have seen the following questions :
How to run flutter app in background continually?
How can I make my flutter app run in background without stopping?
How to create a service in Flutter to make an app to run always in background?
and many more and so far nothing seems to work.
I have written this code for now :
Future<void> _run_app_in_background() async {
final config = FlutterBackgroundAndroidConfig(
notificationTitle: 'MEDICA',
notificationText:
'MEDICA is running in the background',
notificationIcon: AndroidResource(name: 'background_icon'),
notificationImportance: AndroidNotificationImportance.Default,
);
var hasPermissions = await FlutterBackground.hasPermissions;
hasPermissions = await FlutterBackground.initialize(androidConfig: config);
final backgroundExecution =
await FlutterBackground.enableBackgroundExecution();
}
but it seems to be doing nothing and the same with other packages.
So how can I make my app run in background to keep listening for the Bluetooth data sent by device.
Edit:I want this to run on both Android and iOS and if possible maybe someone can suggest me another framework apart from Flutter (in comments maybe) and I can search the internet for the same.
#HrishabhNayal Hello bro Try this way!
https://medium.com/dlt-labs-publication/flutter-run-code-in-the-background-461b4d6c635b
I have developed apps for screen mirroring one is for server and other is receiving server's screens.
Now, i am working on adding Touch events in receiver app and send touch event to server app. As both apps are on different devices so i am making connection using DLNA protocol for the communication.
But i am not able to inject touch event from receiver to server app and not able to achieve the functionality. I want to inject touch events without rooting my devices.
Following is the code that i am using:
m_Instrumentation = new Instrumentation();
AsyncTask.execute(new Runnable() {
#Override
public void run() {
//TODO your background code
m_Instrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,x, y,0));
m_Instrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,x, y,0));
}
});
The above code giving error that is Request Permission to inject event
As inject_event permission is a system permission so i have to make app as system app. For making system app i have to sign app with system certificates. So i followed the link How to compile Android Application with system permissions And if i am able to generate app as system app then i have to install it as /system/app
but when i am searching for adding app as system app then is asking for root device to get read/write access from OS. But i don't want to root the device.
Any helps would be appreciated deeply.
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.
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');
});
}
I have an application built using PhoneGap (Android) that is essentially a shell for a web app, that would (in the future) allow for push notifications and offline reading of downloaded pages from the web app.
My problem is this - if the connection to the network is lost or turned off in the middle of use, and a link is clicked on a page, there is an error: Application Error: Could not find url: '...', and the app closes. I want to be able to prevent the app from closing, and if possible, change this error message.
I know that the standard would be to use the PhoneGap API to check the network connection, then handle it myself, but because this is a shell for a web App, the only place I can do this is on app startup. What are my options?
I would start by checking out the source code for the childbrowserplugin.
The code there for onlocationchange is allowing for intercepting all webrequests in and out of a webview. It sounds like your app has needs similar to this.
For that you have to add the permissions for wifi,Gps,Internet into the Android Manifest file. While you have to add the code for checking the Internet Connection available condition into you code as well..
If both the connection doesnot fullfills then try to add the toast message that Internet connection is not available..
I think your problem will definitely be solved...