How do I check if the Wi-Fi is connected on Android?

Asked 2 years ago, Updated 2 years ago, 113 views

If I'm not connected to Wi-Fi on the app, I'm trying to prevent the file from being downloaded. I don't know what to do. Help me.

android android-wifi wifimanager

2022-09-21 18:32

1 Answers

In the Android manifest file, <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> Please add this.

Check connection

ConnectivityManager cManager; 
NetworkInfo mobile; 
NetworkInfo wifi; 

cManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 
mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 
wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 

if(mobile.isConnected() || wifi.isConnected())
{
    //3G or WiFi connected 
}

You can do it like this.


2022-09-21 18:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.