If you just want to check whether the network is connected, use it directly isNetworkConnected() If you want to check the network connectivity (whether the network can be accessed), then use isNetworkConnected() in combination with isNetworkOnline()
Personal experience, don’t spray if you don’t like it. . . I never care whether the user is connected to 3G, 4G or WIFI, and I don’t care whether the WIFI is connected to the Internet, because it doesn’t matter. The key point is whether the user’s App can connect to the designated server. So... Just test the connection to the server directly. If there is no Internet connection, an exception will be thrown quickly. Try catch and you will know. Or write a dedicated API for testing connections.
Write a method directly and visit http://www.baidu.com. If data is returned, it means there is a network. If no data is returned, or an exception means there is no network. so
public static int getNetWorkStatus(Context context) {
If you just want to check whether the network is connected, use it directly
isNetworkConnected()
If you want to check the network connectivity (whether the network can be accessed), then use
isNetworkConnected()
in combination withisNetworkOnline()
Personal experience, don’t spray if you don’t like it. . .
I never care whether the user is connected to 3G, 4G or WIFI, and I don’t care whether the WIFI is connected to the Internet, because it doesn’t matter.
The key point is whether the user’s App can connect to the designated server.
So...
Just test the connection to the server directly. If there is no Internet connection, an exception will be thrown quickly.
Try catch and you will know.
Or write a dedicated API for testing connections.
Write a method directly and visit http://www.baidu.com. If data is returned, it means there is a network. If no data is returned, or an exception means there is no network. so