This is a migrated thread and some comments may be shown as answers.

Check network connectivity

3 Answers 376 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 25 Mar 2013, 11:45 PM
Hi I'm just doing some research. Is it possible to detect if the app is connected to the internet and what type of connection it specifically is it wifi? Cheers, Chris.

3 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 26 Mar 2013, 07:49 AM
Hi Chris,

Check this Cordova API for Connection in Documentation to get the connection type.

And to detect when your application switch between online and offline state hook up to the corresponding events (see Cordova Events Documentation).

Greetings,
Jordan
the Telerik team

Share feedback and vote for features on our Feedback Portal.
Want some Kendo UI online training - head over to Pluralsight.
0
Markus
Top achievements
Rank 2
answered on 29 Aug 2013, 01:10 PM
Better late then never. Code might help someone.

Markus

app.checkConnection = function()
  {
      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';
 
      $('#sp_connection_type').text(states[networkState] + " " + device_language);
      if (states[networkState] == 'No network connection') {
                     navigator.notification.alert(
          'No active connection found!',
          oppenSettings,
          'Network ',
         'OK'
          );
           
      }
  }
 
    // I wanted a confirm button first opening setting,
     // but not available now
  function oppenSettings(buttonIndex) {
  if (buttonIndex == 1) {
    // alert("we do something");
  }
  else {
  // alert('we do nothing! ');
  }
0
jaweria
Top achievements
Rank 1
answered on 18 May 2016, 08:09 AM

can we use Broadcast receiver in ionic framework?

i want to show toast when network is connected.. is it possible in ionic framework

Tags
Apache Cordova
Asked by
Chris
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Markus
Top achievements
Rank 2
jaweria
Top achievements
Rank 1
Share this question
or