Reputation: 8233
I'm currently building an Angular app for Android / iOs (with Cordova).
I'm encountering an issue : the app have to work when the device is offline. On iOs, when I switch the device offline, it's ok.
On Android (real device on 4.1), if I put the device offline and come back to the app, it alerts me that the app have crashed.
I dont know where I can find any log about what happens, any help would be great :)
Here's my config.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<widget id="fr.menutab.app" version="0.0.1">
<name>App title</name>
<description>Not yet</description>
<author email="[email protected]" href="http://cordova.io">
Author
</author>
<!-- PLUGINS -->
<feature name="Device">
<param name="ios-package" value="CDVDevice" />
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="Console">
<param name="ios-package" value="CDVConsole" />
</feature>
<feature name="File">
<param name="ios-package" value="CDVFile" />
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="ios-package" value="CDVFileTransfer" />
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<!-- PREFERENCES -->
<preference name="target-device" value="universal" />
<preference name="Orientation" value="landscape" />
<preference name="Fullscreen" value="true" />
<preference name="phonegap-version" value="3.3.0" />
<!-- ACCESS CONTROL -->
<access origin="*" />
</widget>
Tell me if you need to see more code :)
Upvotes: 0
Views: 1660
Reputation: 1574
I was having this same problem. Found this article on problems updating to cordova 3.5.0.
http://excellencemagentoblog.com/cordova-3-5-0-update-troubleshooting-android
The fix that worked for me is at the bottom of the article:
cordova plugin remove org.apache.cordova.network-information
cordova plugin add https://github.com/apache/cordova-plugin-network-information
Upvotes: 2
Reputation: 10100
You can try with "Offline" Event.
The event fires when an application goes offline, and the device is not connected to the Internet.
document.addEventListener("offline", yourCallbackFunction, false);
The offline event fires when a previously connected device loses a network connection so that an application can no longer access the Internet. It relies on the same information as the Connection API, and fires when the value of connection.type becomes NONE.
Applications typically should use document.addEventListener to attach an event listener once the deviceready event fires.
Example :
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("offline", onOffline, false);
}
// Handle the offline event
//
function onOffline() {
}
</script>
Source Link : http://docs.phonegap.com/en/3.1.0/cordova_events_events.md.html#offline
Hope this helps.
Upvotes: 1