I want to check if my android device connected to which network (either wifi, home network, or mobile network) and then I want to use different the url link (use to send data to server) depends on which network the device connected. I'm new to android, and I already googled it but doesn't seems to find the answer or because of my limited vocabulary. Can anybody help me?
Asked
Active
Viewed 255 times
1
-
https://stackoverflow.com/questions/2802472/detect-network-connection-type-on-android This post may answer your question. – João Paulo Sena Jul 26 '18 at 02:35
1 Answers
0
try to use this mate
final ConnectivityManager connMgr = (ConnectivityManager)
getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifi.isConnected()) {
//do what you want
} else if (mobile.isConnected()) {
//do what you want
}
and dont forget to put this on your AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

Rubick
- 296
- 3
- 22
-
thank you! I solved the problem, get the wifi ip address and then check if wifi connected with specific ip address and then do other activity. – pdiani Jul 26 '18 at 06:29