B4A Library WaitForInternet - Best way to check the internet connection

WFITop.png


This library was inspired and based on WaitForTheInternet by César Pérez
https://github.com/ouvigna/WaitForTheInternet

Your application will be able to get through an event, as it connects to the internet via Wifi or 3G, without the need to be checking all the time, not consuming battery unnecessarily.

Installation instructions:
- Copy the .xml and .jar(s) files to your custom libraries folder
- Select in your REFERENCED LIBRARIES



Version history:
V1.0.0 (First public release - Donationware):
- Initial version


WaitForInternet
Author:
Alberto Iglesias - alberto@visualnet.inf.br
Version: 1.0.0
  • WaitForInternet
    Events:
    • onInitialized ()
    • onReceived (Action As String, WifiAvailable As Boolean, WifiConnected As Boolean, WifiRoaming as Boolean As , MobileAvailable As Boolean, MobileConnected As Boolean, MobileRoaming as Boolean, ExtraNetworkInfo As String, HostFound as Boolean)
    Fields:
    • JavaDebug As Boolean
    • PingHost As String
    • PingHostOnReceive As Boolean
    • PingResult As String
    Methods:
    • About As String
    • ForcePing As Boolean
    • Initialize (eventname As String)
    • Version As String
    • isConnectedToInternet As Boolean
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.ACCESS_WIFI_STATE
    • android.permission.INTERNET



* In the Full Version, you have a double check for then internet connection over the ping method to bypass Captive Portals and have a ForcePing Method to check the host connect in any time you want.
Please consider a simple €10 donation and I send to you the Library with this features.

Check all Libraries in: http://vnsoft.es/store/
 

Attachments

  • Example1.zip
    13.2 KB · Views: 740
  • WaitForInternet101.zip
    6.4 KB · Views: 682
  • WaitForTheInternet102Demo.zip
    6.5 KB · Views: 557
Last edited:

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Imagine you have in a company connected to internet behind a firewall and with a captive portal (to put your username and password to connect, like a Mac Donald´s connection for example).

When you connect you can´t navigate to others urls without pass the authentication screen, right?

So, the android interpret this connection like "CONNECTED" but you don´t! You just connected to WIFI.

And to connect others URL´s you need to pass this authentication, and then you can...

and the PING method allow you to check if you REALLY is the internet!
 

Rusty

Well-Known Member
Licensed User
Longtime User
Aha! Now I get it :)
Thanks!
I'll purchase your lib right now.
Good work Alberto!
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Alberto,
I purchased your library from your Visual Net Store
Order #223
How do I download the production library?
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
I received "Your order is complete"...Order @223, which is a receipt. No URL or link (other than my email address)
I received "Welcome to Visual Net Store"...thanks for creating an account.
That's all.
No links to download or anything else...
Rusty

Paypal indicates that you have already been paid...
 

Rusty

Well-Known Member
Licensed User
Longtime User
Alberto,
I received the zip file you sent me, but it contains a demo library and the compiled program will not allow a ping.
Can you advise?
Rusty
 

coslad

Well-Known Member
Licensed User
Longtime User
Hi Alberto

i want to try your lib , where can i download 1.02 Version ? the url :

http://worknhouse.com/store/product/waitforinternet-best-way-to-check-the-internet-connection/


is down , and at the first post there is the V 1.01 .

i tried the 1.01 but it come out this error :

B4X:
Network WIFI connected
WifiAvailable:true
WifiConnected:true
Ping not available in Demo Version.** DONATIONWARE **
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 (has extras) } in com.visualnet.waitforinternet$1@4307d550
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:773)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:175)
    at android.app.ActivityThread.main(ActivityThread.java:5279)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at com.visualnet.waitforinternet$1.onReceive(waitforinternet.java:176)
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:763)
    ... 9 more
Thanks
 
Last edited:

coslad

Well-Known Member
Licensed User
Longtime User
Ciao Alberto

even with 1.02V i got the same error :

B4X:
** Service (comunicazione) Start **
Network WIFI connected
WifiAvailable:true
WifiConnected:true
Ping not available in Demo Version.** DONATIONWARE **
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 (has extras) } in com.visualnet.waitforinternet$1@4307c758
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:773)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:175)
    at android.app.ActivityThread.main(ActivityThread.java:5279)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)
    at com.visualnet.waitforinternet$1.onReceive(waitforinternet.java:199)
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:763)
    ... 9 more

my is a Samsung tablet without 3G module.
 

coslad

Well-Known Member
Licensed User
Longtime User
Albe' !!

The same app running well on a S6 , but if i run it on a device without 3g it crash , i'll try some update but i don't think it is the problem.
 

Peekay

Active Member
Licensed User
Longtime User
Alberto,

Thanks so much. I downloaded the version for 4.99 pound, which is more than enough for me, thanks.
Must I pose questions to your message box directly?
Must I also have your layout as a sort of settings panel in my app, or must I only use the code for it?

PK
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I tried your demo on a Samsung Galaxy Tab A7 (SM-T500) Tablet and got the following results

1625068209255.png


The problem is the device does have a WiFi IP (connected to the router using WiFi) but the Router has NO Internet connection - My internet is down right now.

ALSO: The Tablet does NOT have Mobile/3G just WiFi

IS the only way to know for sure if connected is to use the version that pings?
 
Top