This post details about the code required to implement to check if you have an internet connection or whether you are connected to active network and what is the type of network such as WiFi or Ethernet so that you can perform network dependent tasks with assured success or show failure cases to the user if network is not connected or gets disconnected in runtime.
You can also use following code as reference to do additional check and identify type of network as well as IP Address of the device.
Check Network Type if its Stable network [ Ref. MediaResourceGetter.java from Samsung github ]
Check Local Network IP Address [ Ref. oracle docs]