The following Content will show you how to make use of social media sharing in your Android and Windows and iOS mobile application using Ionic Framework.
1.Create the project
ionic start Test blank
cd Test
ionic platform add android
2.Add Plugin
This plugin provides an implementation of an old version of the Network Information API. It provides information about the device's cellular and wifi connection, and whether the device has an internet connection.
This plugin not supported in browser for testing build in device.
cordova plugin add cordova-plugin-network-information
Until Cordova 2.3.0, the Connection object was accessed via navigator.network.connection, after which it was changed to navigator.connection to match the W3C specification. It's still available at its original location, but is deprecated and will eventually be removed.
3.Implementation
In your index.html nothing to change for testing purpose you just need to add following code in your app.js to showing network connection problem.
app.js
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
// Check for network connection
if(window.Connection) {
if(navigator.connection.type == Connection.NONE) {
$ionicPopup.confirm({
title: 'Network Problem',
content: 'Sorry, Please Check Your Network Connection.'
})
.then(function(result) {
if(!result) {
navigator.app.exitApp();
}
});
}
}
});
})
4.Build or Run It
ionic build android or
ionic run android
NOTE:
Here , the connection object, exposed via navigator.connection, provides information about the device's cellular and wifi connection.
Available more constants with it as follows ,
- Connection.UNKNOWN
- Connection.ETHERNET
- Connection.WIFI
- Connection.CELL_2G
- Connection.CELL_3G
- Connection.CELL_4G
- Connection.CELL
- Connection.NONE
Simple example for connection.type
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';
alert('Connection type: ' + states[networkState]);
}
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';
alert('Connection type: ' + states[networkState]);
}
Dropped internet connection is really a big problem. A reliable connection is always needed. The internet service provider Reno should be careful about this and give support to clients.
ReplyDelete