Check Internet Connection In App Inventor

Checking connection is very easy. You can use a Web component and try connecting to a website. is a very good candidate for that since it’s very unusual for google server to be down. Below is a snippet where I have a button and when you click the button, it tries to connect to You can download the project CheckConnection and try changing the google url to something that doesn’t exist and see the result. Say if you set the value of the variable googleUrl to, you will have a 404 error. If the responseCode sent from the server is 200, that means you have connection.

For a list of response codes and what they mean, see HTTP status codes.

Here’s the project source – CheckConnection



  1. Hello,

    I’m looking for a way to such action, whether it is possible to:

    a) when you start Screen1, the application checked if an active internet connection, if so OK, run Screen2

    b) if there is no Internet connection, run Screen3

    I thought your code to check for my needs. Unfortunately does not work as it should, there is an error code 1101 for the server. I can customize it to my needs.

    Please help, thanks Tom

    • Did you try this on a device? You should test connection related apps on your device. You can try first the sample CheckConnection provided above.

  2. Hello again,

    I thank you for your help;) objective achieved. My code is able to:

    First checks the Internet connection (Screen1)
    2 if there is an active Internet connection, launches Screen 3
    3 if there is not an active Internet connection, launches Screen 2

    I will try to fine-tune the code to my needs.

    Regards, Tom

    • I’m looking for a solution like yours. U have to send me the maid to file aia have a study .

  3. Hi,
    I have a question, how to build the code in the app inventor not inventor2? Is it possible, I can not odnaleść ingredients to inventor2?

    Regards, Tom

  4. hi,

    Thank you for your help again;). After a large reconstruction of the code, I got what I was looking for. You are great

    Regards, Tom

  5. Can i call ajax request xmlhttp request from app inventor

  6. Hi,
    I have a question, how can i read the unique ID of an NFC tag on android, please (App inventor 2)

    Regards, Kato

  7. Hi,
    I have a question,how can I post a username and password to a website..?
    Is it possible in appinventor..?

    • You can build the url with necessary data. Do a search in google. This has been explained in many sites.

  8. Hi, have you tried this app on Lollipop ? I’ve tried it on a Nexux 5 with lollipop and it doesn’t seems to work. It shows that he doesn’t have internet connection, even when the device is connected. Any ideea why ? On other Android versions the app works perfect.
    Thank you.

  9. The ResponseCode from when you are using Web.Get on Lollipop is 302, not 200, and so, the answer of the App is that you have no internet connection, even if you are connected. Do you know how can i check the Android version in Appinventor, so i can modify the ‘IF condition’ acoording to it ?
    Thank you very much for your answer.

    • 302 is valid with redirection. Modify the ‘if’ statement to “if responseCode=200 or responseCode=302”, it’s good.

  10. Ok. I’ll do that. I thought that 302 is a real error, not an ‘OK’answer. I was already looking for another way to check the internet connection, no way I was thinking about implementing this very simple solution (so stupid of me:) ). Thank you very much, again. By the way, there is some kind of method in appinventor for sending a ‘ping’ message to an IP and check if you get the reply ?
    Thank you !

    • It does work. It sends 302 for redirect and 200 for final entry. Since we only catch the first response, we get 302.

  11. This doesn’t work anymore. I had it working just fine on an old app, needed it in a new one, and it fails. I tried the old app, doesn’t work either. I get an Error 1101, unable to get response. Can you help me with a sollution

    • You need to upgrade your companion first.

  12. Thanks Sajal for this tutorial!
    It’s working on Android 5.1 adding “if responseCode=200 or responseCode=302″.

    Have you done in App Inventor an Internet speed meter?

    Thanks again!

    • There are too many variables involved to do that. Do a search online and you will see what I mean. An example is – while you are making the speed test, say device is scheduled to fetch mails in the same time. Your speed test will be affected.

  13. Hi
    First thanks For Sharning and i useing your source code “CheckConnection” i want this app ping evrey 1 min ,What should I do?

    • Have a Clock and set its interval to 2000 ms. Then every time Clock fires, ping.

  14. First of all, thank you for sharing

    I want change “CheckConnection” it, for example, every 1 minute ping and, if conection down show a msg

    what should I do?

  15. Thank you very much for your response
    and how to i can get ,(for example), 3 website from textbox and app ping all web sit in order?

  16. Thank you very much for fast response
    how to run app in background?

  17. Oh,That’s no way?

    I have some questions that I did not find in your post:

    What is a Code for Error connect to the Internet?

    How do identify that a site is busy (responseCode)?

    What is a responseCode for Down URLs?

    this Is code are reliable?

    Thank you

  18. I have a texbox for Enter url from user,When i,press Button home on the my Phone to visible screen,and again restore it,textbox is clear!!do you have solution

    Thank you

  19. hello, i want to build voltmeter by using apps and internet. Do you have any suggestion to build it if i want to read data of voltage from circuit that i created on arduino. means that data from arduino will send to android phone using mit apps inventor 2 using internet.

  20. Hi Sajal. Is there a way to diactivates the Error 1001 Message? Or it always will be displayed when no internet connection was detected?

  21. Hello Sajal, thanks for the tutorial and the example provided.
    Im actually using Thunkable, spin off AI2, and i have Screen1 Webviewer component.

    I would like that if there is no connection the app will go to Screen2 where i had put two textbox.

    Please can you help me how i can achieve that?

      • Uhm seems nothing happening Sajal. If there is no connection the app does nothing, just show the default webview error message.

        I just added the web1 component in the designer and the 2 blocks to my Screen1

        • I misunderstood. I thought if connection is successful, you want to launch another screen. You want other way around. In web1.GotText, have a if statement where it checks if the response code is NOT 200. If not 200, open your other screen. Do the same in errornumber=1101.

          • Yes Sajal i want in the other way.
            But the problem is that the Web1 seems is not triggered when the app open.
            I added When Screen1.OnInitalize do call Web1.get but with no success, where im wrong?
            If you want i can provide the .aia app file (but don’t know if it’s compatible with AI2 as i created in Thunkable)


  22. @Simone, send me your .aia. Hopefully that will open in ai2.

    • You didn’t set the Url of Web1. Try setting it to as I did above in the tutorial. Use an actual device to test, not an emulator. Everything should work unless something is wrong with thunkable thing that you used which I have no idea about. Contact them.

  23. Ok i will try Sajal, but something isn’t clear to me, why i have to set the Url of Web1 if i already set an Url in the WebViewer component?
    I just want that if there is no connection the app will go to Screen2, if there is connection it will display the content of the WebViewer component.

    • Web viewer has nothing to do with web. Viewer just views a page like a browser while web is much more. It can post a request, fetch a server response, etc. web is used to get a response from any server. In my tutorial, I chose google.

      • I solved Sajal! Thanks for all the support.

  24. Thank you for this post.

    I am trying to open a URL that does not exist. For some reason screen1.erroroccured event is not triggered. Only when I disable the DATA on the phone it is triggered. Do you know why and how to resolve?

    • See first what response code you get. I provided a link in this tutorial to see what those response codes mean. You should receive 404 (not found). By the way, having no connection is not an error. It’s a state.

  25. Hello.

    In app inventor 2 is possible to check if the user using WiFI or 4G?

    • I am afraid you cannot. Look for a site/api that checks if the mobile network is 3g/4g/etc and use that.

  26. I want make an app that itself starts as user turn on data connection like whats app , hike .
    Please provide solution and also want to know that how it can be run inside without user permission

  27. I want to.make app which should start as user turn on data connection.

  28. Hi Sajal,
    I am working on an project where i need to pass a hostname in the url instead of the IP Address. Is it possible in App Inventor.
    Is there a way of getting the IP of the HOST using getByName() or some other java method.
    Any pointers in this direction will help.

  29. i am unable to use check connection

  30. sir can you help me?
    i’m trying to create a simple registration (part of my app),
    i’m sure that the db credentials is correct and when running the app doing registration, it returns “SUCCESS” but the data isn’t save on my database what i’m doing wrong?
    php script:
    im really don’t know what to do know and can’t find solution on the internet
    i hope you can give me some tips sir
    thank you very much

  31. Hi Sir,

    Can you help me to send sms using app inventor while compiling it gives error only one screen i checked it gives error ie.ymail.
    i googled but didn’t get result.

    • Can you please post the error screenshot here?

Submit a Comment

Your email address will not be published. Required fields are marked *