SoFunction
Updated on 2025-03-11

How to check whether the phone and wireless are connected

This article describes the implementation code for Android to check whether the mobile phone and wireless are connected, and is shared with you for your reference. The specific methods are as follows:

Method 1:

The main function codes are as follows:

Copy the codeThe code is as follows:
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = ();
if(info!=null && ()){
return true;
}else{
return false;
}

Method 2:

The main function codes are as follows:

Copy the codeThe code is as follows:
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int state = ();
if(state == TelephonyManager.DATA_CONNECTED){
urn true;
}else{
urn false;
}

Method 1: You can check the mobile phone connection or the wireless connection status of the mobile phone

Method 2 can only check the connection status of the mobile phone, but cannot check the wireless connection status of the mobile phone (that is, if the mobile phone does not have a mobile phone card, but the wireless connection is connected, it will also return false)

I hope this article will be helpful to everyone's Android programming design.