Connecting to internet from your mobile phone is important so we can surf the world wide web. However, sometimes we have connection issues but without knowing. Let us try to create a simple APP to check the connection status.
Connection Status
- In this project, we will try to connect to web url google.com to make sure our connection status is ok.
- The design components needs:
- 1x Notifier; 1x Button; 1xLabel; 1xImage; 1xWeb
- Rename Label – txtResult, Button – btnConnect.
- Upload 2 images for connect and disconnect.
- Initialize a global variable google url to http://www.google.com
- Add a procedure – Connection set the web component to google url. Then call the web call Get function.
- When BtnConnect.Click is called, set the txtResult.Text to “Checking”. Then call Connection procedure.
- When Web.GetText, check for response code
- If “200“, set the txtResult.Text to “Connection Successful”. Change to connect image
- If “404“, set the txtResult.Text to “Webpage is not found!!”. Change to disconnect image
- Else, set the txtResult.Text to “Other connection error!”. Change to disconnect image.
- Screen1.ErrorOccurred, get ErrorNumber = 1101, then call notifier.ShowAlert to “Connection Error” else “App Error”
- 1101 stands for “Unable to get a response with the specified URL: %s”
Finally, HTML error code, we focus on the not found. Here is the list of errors. Another is the App Inventor handle of the error Number for connection url response issue. Here is the list of app inventor errors. Below is our demo screen.
Take care and good luck.