I want to make a call, but before this operation I must be sure the mobile network is available and that the phone is not in flight mode.
How can I do this?
I want to make a call, but before this operation I must be sure the mobile network is available and that the phone is not in flight mode.
How can I do this?
You need to use ACCESS_NETWORK_STATE
permission in your manifest and then use this:
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
// if no network is available networkInfo will be null, otherwise check if we are connected
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
return false;
}
For all types of connections you can try to use this(java script
) :
function checkConnection() {
var networkState = navigator.network.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.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
The connection object gives access to the device's cellular and wifi connection information.
References:
vogelle-de
how to programmatically check availability of internet connection using jquery