0

I am creating an application to check the status of the mobile network.

I use NetworkInfo.State.CONNECTED to check the connectivity. It works fine on my emulator. But when the user makes a call the Network info state is SUSPENDED(But the user is connected to the network) What does the suspended code indicate?

Also when I run the application on a device, the network state is given as DISCONNECTED. But the user is connected to the network and can recevice/give calls. The NetworkInfo.getReason() is given as datadisconnected in this case.

Can someone please help met o check the mobile connectivity to the network.

Thanks in advance.

ShwetaK
  • 180
  • 4
  • 14

1 Answers1

1
public class NetWorkCheck{
    ConnectivityManager connectivityManager;
    NetworkInfo wifiInfo, mobileInfo, lanInfo;


    public Boolean checkNow(Context con){

        try{
            connectivityManager = (ConnectivityManager) con.getSystemService(Context.CONNECTIVITY_SERVICE);
            wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            mobileInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


            if(wifiInfo.isConnected() || mobileInfo.isConnected())
            {
                return true;
            }
        }
        catch(Exception e){
            System.out.println("CheckConnectivity Exception: " + e.getMessage());
        }

        return false;
    }
}
mukesh
  • 4,140
  • 5
  • 29
  • 40