I was having the same problem days ago. While I could not find best solution. I have created a new cordova plugin that you can use to get most of the basic network informations you need.
All you have to do is to run this command
cordova plugin add cordova-plugin-network-signal-strength
Usage
The API has only one method window["networkSignalStrength"].networkInfo(infoType, callback).
infoType parameter could either be:
null : to get all the network details including signal strength, network type and connection state
CONNECTION_STATE : to get only the connection state which will return 0 or 1.
0 : disconnected
1 : connected
SIGNAL_STRENGTH : to get only the signal strength information.
This return an object which include rssi, rssq, rssnr, rsrp, signal level and lte level
signal type range:
- RSSI: [-113, -51, "dBm"]
- RSSNR: [-20, +30, "dB"]
- RSRQ: [-34, 3, "dB"]
- RSRP: [-140, -43, "dBm"]
NETWORK_TYPE : to get type of connected network. Return integer -1 to 5
- -1 : unknown
- 0 : disconnected
- 1 : wifi
- 2 : 2g
- 3 : 3g
- 4 : 4g
- 5 : roaming
code snippet
// to get full network information
window['networkSignalStrength'] ? .networkInfo(null, (networkInfoData) => {
console.log('network signal data :', networkInfoData)
});
/**
You receive -1 as a result if the device is unable to get a known network
type and 0 for offline or disconnected state.
*/
// to get only signal strength
window['networkSignalStrength'] ? .networkInfo("SIGNAL_STRENGTH",
(networkInfoData) => {
console.log('network signal data :', networkInfoData)
});
/**
You should call the window.SignalStrength.dbm only after cordova platform is
ready. Example in Ionic framework:
*/
// ensure platform is ready before calling the plugin method
$ionicPlatform.ready().then(() => {
// Platform now ready, execute any required native code
setInterval(() => {
window['networkSignalStrength'] ? .networkInfo(null, (networkInfoData) => {
console.log('network signal data :', networkInfoData)
});
}, 5000)
});
cordova-plugin-network-signal-strength