InternetAvailabilityChecker
InternetAvailabilityChecker copied to clipboard
What if i remove internet cable from wifi router
Hi Ankit, What if I remove internet cable from wifi router. I am not getting any callback.
My mobile is connected to wifi of router only internet cable is removed from router.
Is this feature supported or not?
No, it is not supported. I couldn't find any way to get such callback. Android provides callback whenever there is any change in connectivity. I will try to find some solution for this and will update here. Thanks for reporting this @yudhisthira123 :)
this lib can`t support in 28sdk
@arudakiya Sorry for the late response. I am updating this library and you will be able to use it with 28+ sdks soon.
@arudakiya Fixed the issue with sdk 28+. Please refer to this commit: efa685873aec38023821979985117ca831f55672
Hi @AggarwalAnkit , in this scenario (if the internet cable is removed from router) you can check internet connection by below method.
public static boolean isOnline() { Runtime runtime = Runtime.getRuntime(); try { Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8"); int exitValue = ipProcess.waitFor(); return (exitValue == 0); } catch (IOException | InterruptedException e) { Log.d(TAG,"Execution: InternetConnectioin Exception : "+e.getMessage()); e.printStackTrace(); } return false; }
@zia-ict the issue is I am not sure if we get a callback in the receiver when internet cable is removed. I don't know the trigger point that is the issue. I we can get the callback somehow then, what this library is doing is fine and will tell if internet is available or not exactly.
@zia-ict thanks for reminding me of this issue. Will check it whenever I get time 😃
Hi @AggarwalAnkit , If I first connect to other wifi devices (ex: printer, IFE Router, ..) rather than internet router & open App then your library can't trigger onInternetConnectivityChanged(boolean isConnected) method. Please fix this.
Hi @zia-ict I have fixed the issue which you mentioned regarding connecting to wifi devices rather than internet router. See this commit. The only issue is since it is not connected to internet I am getting this status after some time (actually taking more time than expected). I have set connection timeout also but don't know why it is taking time. I will check it when I get time. If you have any suggestion or solution then you can raise a PR. Thanks 😊