android – How to implement cordova-plugin-networkspeed for cordova app?-ThrowExceptions

Exception or error:

I am trying to know if my Cordova app has an internet connection or not.
Cordova has plugin Cordova-plugin-network-information which shows the network status of the mobile phone.
If it’s mobile network or wifi is on and connected but doesn’t tell if the connection has internet.

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]);

But this doesn’t check if the connection is established to the internet.

So I found this Plugin which checks the connection and return the speed of the network but I am not able to implement it and couldn’t find anything on the internet.
Please provide some solution.

Thanks in advance.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *