3

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sabrina
  • 2,531
  • 1
  • 32
  • 30

1 Answers1

1

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

Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167