App Inventor Extensions: WiFi | Pura Vida Apps

App Inventor Extensions


WiFi Manager Extension

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.

Dec 22th, 2015: Version 1: initial release.

July 7th, 2016: Version 2: macAddress method added.

Aug 11th, 2016: Version 2a: avoid DX execution failed error: build each extension separately

Nov 27th, 2016: Version 3: BSSID method added

Feb 25th, 2017: Version 3a: bugfix IllegalArgumentException: Receiver not registered: null while switching screens

May 10th, 2017: Version 3b: bugfix IllegalArgumentException: Receiver not registered while switching screens

Aug 14th, 2017: Version 4: correspondingRSSIs, SignalStrength, ConnectionInfo, Is5GHzBandSupported added

Aug 16th, 2017: Version 5: correspondingBSSIs added

Dec 6th, 2017: Version 5a: bugfix configuredSSIDs, see also here. Thank you Edgar for the error report.

Dec 14th, 2017: Version 5b: bugfix ConnectSSID, see also here. Thank you again Edgar for the error report.

Apr 8th, 2018: Version 6: new method AccessPointIP added

Apr 13th, 2018: Version 7: connect without password

Aug 29th, 2018: Version 8: Disconnect method added

Nov 6th, 2018: Version 9: Dnsservers method added

Jan 23th, 2019: Version 10: SDK 26 update: dangerous permission android.permission.ACCESS_COARSE_LOCATION removed. What is a dangerous permission? The method AvailableSSIDs including its corresponding event have been removed.

Jan 28th, 2019: Version 11: AvailableSSIDs added again. Additionally example project provided about how to use it together with the location sensor and GPS enabled.

Oct 21th, 2019: Version 12: AfterWifiNegotiation event added

Oct 21th, 2019: Version 13: RemoveSSID added

Oct 21th, 2019: Version 14: LocalIP: returns wifi ip if its enabled else the cellular one

May 25th, 2021: Version 14 recompiled, see also here.

Nov 12th, 2021: Version 15: android.permission.ACCESS_NETWORK_STATE added for App Inventor nb188 release, see also here.

Description

Some useful blocks to use in a wireless lan.
Required permissions: android.permission.ACCESS_WIFI_STATE, android.permission.CHANGE_WIFI_STATE, android.permission.ACCESS_NETWORK_STATE

Properties


Returns whether Success Message should be suppressed.


Specifies whether Success Message should be suppressed.


Returns whether Warning Message should be suppressed.


Specifies whether Warning Message should be suppressed.

Methods


Return the local IP Address. Returns wifi ip if its enabled else the cellular one.
Sponsor of this block is Marius. Thank you!


Return the MAC Address of the device.
Sponsor of this block is Niko. Thank you!


Get current WiFi state: true or false.


Enable WiFi.
You can hide the success message after setting the suppressSuccessMessage property to false.
Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.
Note: starting from Android 10, this method does not work anymore, see also this stackoverflow answer. For Android 10 you might want to try this Activity Starter solution.


Disable WiFi.
You can hide the success message after setting the suppressSuccessMessage property to false.
Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.
Note: starting from Android 10, this method does not work anymore, see also this stackoverflow answer.


Get current WiFi SSID (Service Set Identifier).

Note; Starting with Android 8.1 (API 27), apps must be granted the ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) permission in order to obtain the SSID or BSSID. Apps that target API 29 or higher (Android 10) must be granted ACCESS_FINE_LOCATION. Also GPS must be enabled. See also this stackoverflow answer.

Therefore just drag a location sensor component into your project and additionally ask for permission ACCESS_FINE_LOCATION.


Get current WiFi BSSID (the MAC address of the access point).
Thank you burrowmoor for being the sponsor of this method.

Note; Starting with Android 8.1 (API 27), apps must be granted the ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) permission in order to obtain the SSID or BSSID. Apps that target API 29 or higher (Android 10) must be granted ACCESS_FINE_LOCATION. See also this stackoverflow answer.

Therefore just drag a location sensor component into your project and additionally ask for permission ACCESS_FINE_LOCATION.


Connect to a SSID (Service Set Identifier).
If you provide a non existing SSID or wrong password, this just will be ignored and the device will try to connect to a known SSID instead.
Note: Starting from version 7 it is also possible to connect to an open network, i.e. a SSID, which does not have a password. Thank you Robert for being the sponsor of this enhancement.

Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.

Note: Android will get more and more restricted. The ConnectSSID method does not work anymore starting from Android 10. According to this Stackoverflow answer: For API30 we can use a new Intent action, for API 28 and below we can still use the old way of adding Networks, but for API29 we have some kind of gray area where I was not able to find a good solution yet.. Meanwhile App Inventor targets API30 and I could take a look into this issue again. If you are interested in sponsoring the update of this method, please contact me by email. Thank you.


Get a list of configured SSIDs (Service Set Identifiers). WiFi must be enabled for this.
Note: starting from Android 10, this method does not work anymore, see also this stackoverflow answer.


Get a list of available SSIDs (Service Set Identifiers). WiFi must be enabled for this.

Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.

Note: Precondition to use this method is to add a location sensor component into your project. Also GPS must be enabled. See the example project about how to use it..

Note: Android will get more and more restricted. In a future Android release the AvailableSSIDs method will stop working, see also this note in the Android documentation: "The ability for apps to trigger scan requests will be removed in a future release."


Get current connection info.
For details, see also WiFiInfo documentation.


Check, if 5 GHz Band is supported. Returns true or false.


Get signal strength (RSSI) in a range between 0 and 100.
This algorithm is used to calculate the signal strength..


Get IP address of the access point.
Thank you Eric for being the sponsor of this method.


Disconnect.
Note: after disconnecting the device might reconnect automatically to the next available known network.
Thank you Wei Zheng for being the sponsor of this method.


Return a list of DNS servers (primary and secondary) of the current network.
Note: The method returns the IP address of the gateway router when DNS is not configured inside the router.
Thank you Gabriel for being the sponsor of this method.


Remove a SSID from the network list. Note: starting from Android M, apps are not allowed to remove networks that they did not create.

Events


Event indicating that Available SSIDs (Service Set Identifiers) have been scanned.
A list of the available SSIDs is provided in parameter availableSSIDs. The SSID having the best signal is provided in parameter bestSSID. A list of the corresponding RSSIs is provided in parameter correspondingRSSI. A list of corresponding BSSIs is provided in parameter correspondingBSSIs.
Thank you Tal for being the sponsor of the correspondingRSSI and correspondingBSSI functionality.


Check if the negotiation with the WifiConfiguration was successful, Returns true or false.

Example App: WiFi Test


Example App: Get Available SSIDs

Note: Precondition to use the AvailableSSID method is

  1. to add a location sensor component into the project
  2. to enable GPS and
  3. to build the app to test its functionality



Screenshot

Test

Tested successfully on Samsung Galaxy A5 (2017) running Android 8.0.

Questions and Answers

Q1: Please check TaifunWiFi.SSID in Android 9. When I build it with Android 9 (Samsung S9), the result of TaifunWiFi.SSID is <unknown ssid>. But, if I build it with Android 5, the TaifunWiFi.SSID works well. Thank you.
A: You might want to try the example project "Get Available SSIDs" downloadable from the download section below, which adds a location sensor into the project to get the permission ACCESS_COARSE_LOCATION. Additionally please enable GPS and try using the method SSID again for Android 9 devices. See also here.

Q2: I used Taifun Wifi Extensio to search & connect to Available wifi network. But my problem rise when I connect using SSID & PASSWORD, the connection never succeeds. But if I set My access point to open network & I remove password from connect extension, the connection establish but only for few seconds & my phone connecting to another configured wifi network. My phone use android 8 api 26.
A: Problem solved. The SSID NAME in my case it must be between 6 to 11 character, the SSID NAME must be start with Character (do not use number for first character), the Password must at least 9 character . Now connection are made successfully. Thank you pjack2021.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Terms and Conditions

Download


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Bitcoin

Thank you! Taifun
 

Download TaifunWiFi extension (aix file)
Download WiFi Test (aia file)
Download Available SSIDs Test (aia file)
Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact