There's no definitive way. You can send requests to known servers and URLs, but if they don't respond, you can't really tell whether the problem is at their end or yours. Even with access to platform-specific APIs like Android's connectivity manager, you can only really tell whether the network interface is enabled. It could still be enabled but not connected to the internet, or connected in some defective way where it can only reach certain addresses.