Software Archive
Read-only legacy content

Internet connection checking is not working in apk file

Spaceforhost_K_
Beginner
813 Views

hai sir,
I am new in Intel XDK. I develop a new app for my company using IntelXDK. In my App i am checking, whether the internet connection is established or not in the device, and there is no internet connection, then exit the app.
Code :
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
      function onDeviceReady(){
    var networkState = navigator.connection.type;
    var states = {};
    states[Connection.UNKNOWN] = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI] = 'WiFi connection';
    states[Connection.CELL_2G] = 'Cell 2G connection';
    states[Connection.CELL_3G] = 'Cell 3G connection';
    states[Connection.CELL_4G] = 'Cell 4G connection';
    states[Connection.CELL] = 'Cell generic connection';
    states[Connection.NONE] = 'No network connection';
    if ((states[networkState]) == states[Connection.NONE]) {
        alert('No Internet Connection. Click OK to exit app');
        navigator.app.exitApp();
    }
}
The code  working fine with IntelXDK App Preview and i convert it into apk using intel XDK Build, its not working....
I enable all the plugins in Cordova Hybrid Mobile App Settings.

0 Kudos
10 Replies
Swati_S_Intel1
Employee
813 Views

You are using intel.xdk.device.ready event, so you need to enable Intel XDK device plugin (on the right side of plugins section).

If you are already doing that send your complete project zip file.

Swati

0 Kudos
Adam_G_
New Contributor I
813 Views

Make sure you have your permissions set.  This same issue happened to me.  Go to the Projects Tab, Select Build Settings, and then set the Domain List to "*" (without the quotes).  Then do a build and try it out.

 

 

0 Kudos
Vicente_Fernandez
813 Views

Hello,

I have the same problem.

Intel XDK emulation works OK. I have installed Intel XDK Device and Network Information plugin. But using my device does not work

Tranks

 

0 Kudos
Swati_S_Intel1
Employee
813 Views

As Adam mentioned make sure you choose proper whitelisting. See this article if you are not sure how to set.https://software.intel.com/en-us/articles/cordova-whitelisting-with-intel-xdk-for-ajax-and-launching-external-apps

0 Kudos
Vicente_Fernandez
813 Views

Hello,
Thanks for the reply.
I'm not sure to have intel XDK properly configured.
I attached a picture with my intel XDK app permissions configuration.

The plugins to this projects are:

Status bar.
Device.
Splashscreen.
NetworkInformation.
IntelXDKDevice.
InAppBrowser.

androidcordova.jpgios.jpg

Thanks for the help

0 Kudos
PaulF_IntelCorp
Employee
813 Views

Choose the W3C option for Android and set the "Network Requests" field to * to get started. Then you can make it more explicit once you have your app working and you know the specific domains you will be using.

0 Kudos
Vicente_Fernandez
813 Views

The external connection works, but I want to show an error when the smartphone is not connected to the Internet.
It works on the emulator, but not on the phone.

Permissions problem?

Thanks

0 Kudos
Vicente_Fernandez
813 Views

Hello,

I found the problem.
Using the Cordova notification plugin works.
I think the intel alert plugin have problems.

Thanks for all and sorry for my English

0 Kudos
olhu_k_
Beginner
813 Views
    I have tried all the given solutions but emulator was fine while the device had nothing. 
By chance the code below worked. I added it here if someone needs.




// Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);
    // device APIs are available
    //
    function onDeviceReady() {
        checkConnection();
    }
        function checkConnection() {
            var networkState = navigator.connection.type;
            var states = {};
            states[Connection.UNKNOWN]  = 'Unknown connection';
            states[Connection.ETHERNET] = 'Ethernet connection';
            states[Connection.WIFI]     = 'WiFi connection';
            states[Connection.CELL_2G]  = 'Cell 2G connection';
            states[Connection.CELL_3G]  = 'Cell 3G connection';
            states[Connection.CELL_4G]  = 'Cell 4G connection';
            states[Connection.CELL]     = 'Cell generic connection';
            states[Connection.NONE]     = 'No network connection';
                if ((states[networkState]) == states[Connection.NONE]) {
        alert('Uygulamayı Kullanman İçin İnternet Bağlantısı Gerekmektedir. Lütfen Bir Ağa Bağlan .');
        navigator.app.exitApp();
    }
        }
0 Kudos
Swati_S_Intel1
Employee
813 Views

Intel XDK plugins have been deprecated, they are available on github but are not maintained. Intel XDK is standardizing on Cordova plugin, so we recommend that you use Cordova plugins and deviceready events (not intel.xdk.device.ready event). As Vincent mentioned, use Cordova Navigator object to get connection and other device properties. For the navigator plugin to work to get connection property you do not need to set any whitelisting. You just need to add the Network Information plugin under the Cordova Plugins in the Plugins Management section.

0 Kudos
Reply