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
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.
© 2024 OneMinuteCode. All rights reserved.