Articles

How we can get network information using phonegap

by Prayag Ch InterviewQueries Read Best Intervie
Hello Friends, Today we will discuss, how to get network information using PhoneGap / Apache Cordova. Here we’re going to use network plugin ( https://github.com/apache/cordova-plugin-network-information ). It provides information about the device’s cellular and wifi connection, and whether the device has an internet connection.

if you want to know to get network information using PhoneGap / Apache Cordova, then,

You have to follow these STEP

Step 1:

Create a new PhoneGap / apache Cordova project & add platform

Step 2:

Add Network plugin using the following commands

For 5.0+

Cordova plugin add Cordova-plugin-network-information

For Older Version

Cordova plugin add org.apache.cordova.network-information

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]);
}
<button onclick="checkConnection()">Get Network Info</button>

This is the code for getting network information using PhoneGap / Apache Cordova. The output of this code will alert your current network type, navigator.connection.type returns network type. you can also use network events for checking the internet connection like online/offline events.

Thanks for reading,

You can also read my blog how to crack an interview, here you can readable and some tips that will definitely help you to crack any  interview level

Sponsor Ads


About Prayag Ch Innovator   InterviewQueries Read Best Intervie

29 connections, 0 recommendations, 82 honor points.
Joined APSense since, June 17th, 2019, From noida, India.

Created on Jan 29th 2020 04:36. Viewed 541 times.

Comments

No comment, be the first to comment.
Please sign in before you comment.