Hi,
I am developing an app and i just want to check network connectivity.but it only detects that device is connected to internet or not.it should also detect if there no internet access.
Iâm sorry, but I canât make any sense out of this. The internet isnât a concrete thing. If you are interested in knowing whether your device can connect to a particular host, try connecting to it. If it works, it works. If it didnât, it didnât.
In my application before displaying data to user.i need to check that device is connected to network or not.
Note-sometime it happens that we are connected to the network but if you try to search something on browser it says âSomething went wrong please check you connection and try againâ.
Maybe your ISP deactivate you account,therefore you canât browse anything .Again keep in you are connected to network using (wifi router,lan cable,etc)
Scenario:
Let device is connected to network,But it canât access/browse anything.
So,it should give me alert "Please check your internet connection ".
But it not displays any alert in this case.
Thatâs your solution. The error message in browser only appears after trying to connect to a website and failing. Without doing that, your app canât know that it does have a network connection, but it is broken.
The only solution which comes to my mind is to have a really dummy backend function in your API, that return true just for calling it.
So you check if your mobile have internet connection via the Network provider, then if success, call your dummy API service (the most simplest call you can make, a GET API call to http://yourdomain.com/checkconnection for example) and if this call is success, then your device is really connect to internet.
I have the same question but i think this need a detalled explication case.
For example: if you have your phone with DATA (When i say data, mean the service that your phone have to access to the internet: LTE, 3G 2GâŚ).
Then, suppose your phone exceed the capacity of DATA that the company gave to you to navegate in the internet. Your phone understand he is still connected to the network but you canât navigate.
Is the same to say: âYou are connected to your houseâs wifi but your wireless router isn´t connected to the Internetâ
And Question is: âHow you detect the phone is connected but not have DATA to navigate on the Internetâ.
At the risk of repeating myself from earlier in the thread, both the easiest thing to implement and what I think makes most sense for these scenarios (including yours) is to try to make a network request to (for example) a simple heartbeat endpoint on a known server. If that request fails, you can probably expect that further ones would as well.
If your question is about phrasing of the error reporting to the user, I donât know of any programmatic way to distinguish between âno network connection at allâ, âconnected to something but that âsomethingâ canât reach the internetâ and âbilling layer problem unrelated to physical networkâ, but perhaps something like âunable to reach necessary network resourcesâ would make sense to the user, and if needed you could list a few possible troubleshooting suggestions including the data cap hit you seem to be concerned about.
Actually, thatâs the option i going to implement. By as you say, i donât know how much stressfull could be this proccess for the phone. But iâll try it and if everything itâs ok, i will tell you.
I implemented the code and work really fine. Just i had to add some extra validation.
The resolution was add HEAD Protocol as control validater before any request you going to make in your application.
Add the beginning if you have âTRUE connectionâ, the HEAD Protocol will returns you a response. But, if you dont have âTRUE connectionâ, the HEAD Protocol donât going to return response. With that behavior, you can make validation of your application connection.