So while developing I turn off the wifi and then the ionic app doesn't work in android device/emulator.
But when I turn off wifi with the released and signed apk file for android app works just fine.
The thing is I need my app to do something when internet connection is off to do something:
if(window.Connection) {
if(navigator.connection.type == Connection.NONE) {
//doSomething();
}
}
But since the app doesn't run on emulator nor device if I turn off wifi there is no way I can test if code worked without having to build a release apk which is very time consuming. How can I make it work even if I turn wifi off?
I get an error message like this:
When you run application with ionic run android -l -c
then all data and resources are being served from your computer through network. In fact in that case it works on mobile in same way you run on computer browser with ionic serve
. So when you turn off mobile internet then it is unable to serve from computer, as network was channel to serve pages. But ionic run android
packages all aplication sources in mobile and resources are served from file:///android_asset/www/
.
Real Purpose of ionic run -l -c :
l
stands for liverload, which keeps on refreshing your application in mobile whenever there is change in source. c
stands for console, application console logs are shown in your command line from where you initiated application. It helps ionic developers for testing, as they do not have to install application again and again. But remember keep your phone connected to computer and both should be on same internet network.
NOTE: Sometimes cordova plugins
like camera etc behave strange in this enviroment. So better use without -l -c
while checking plugins related functionalities.
just solved the issue. I was trying to run the app with ionic run android -l -c
so now I run it with ionic run android
and off course that doesn't need livereload -l
and now app works just fine