WiFi Settings Tutorial in Android using Basic4Android

Hi! this is an another tutorial in Android using Basic4Android that will view WiFi settings in your phone and can customize to enable/disable your WiFi. This tutorial deals with several categories of items:
  • The list of configured networks. The list can be viewed and updated, and attributes of individual entries can be modified.
  • The currently active WiFi network, if any. Connectivity can be established or torn down, and dynamic information about the state of the network can be queried.
  • Results of access point scans, containing enough information to make decisions about what access point to connect to.
  • It defines the names of various Intent actions that are broadcast upon any sort of change in WiFi state.
On this, you need to create two buttons and named it as "btnWifi" to open WiFi Settings and "btnWifiOnOff" for automatic WiFi configuration for disabling and enabling your WiFi. Next, named your abstract design as "main". Your abstract designer will be like this one below: abstract Declare your variable in the Sub_Global like this:
  1. Sub Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4. Dim ph As ICOSPhone
  5. Dim btnWifi As Button
  6. Dim btnWifiOnOff As Button
  7. End Sub
Dim ph As ICOSPhone - ph here is our variable for ICOSPhone in which it has all the necessary libraries in using phone utilities. Dim btnWifi As Button - we use this button to open your WiFi settings in your phone. Dim Dim btnWifiOnOff As Button - we use this button for automatic opening of WiFi Configuration in enabling/disabling your WiFi. Now create a new activity. It should look like this:
  1. Sub Activity_Create(FirstTime As Boolean)
  2. 'Do not forget to load the layout file created with the visual designer. For example:
  3. Activity.LoadLayout("main")
  4. End Sub
Now your activity when run will look like this: first Next, type the following code below. That code means to display the phone device model when our btnWifi will click.
  1. Sub btnWifi_Click
  2. ph.OpenWifiSettings
  3. End Sub
The ph.OpenWifiSettings here is the method used to open your phone's WiFi Settings. When you click this button, it will display like this image below: wifi Next, type the following code below. This code below means to have a shortcut of enabling and disabling WiFi when our btnWifiOnOff will click.
  1. Sub btnWifiOnOff_Click
  2. ph.WiFiOnOff(LoadBitmap(File.DirAssets,"wireless_on.png"),LoadBitmap(File.DirAssets,"wireless_off.png"))
  3. End Sub
The ph.WiFiOnOff(LoadBitmap(File.DirAssets,"wireless_on.png"),LoadBitmap(File.DirAssets,"wireless_off.png")) here is the method used to have a shortcut in enabling and disabling your WiFi and it has two images of WiFi. I already put in this tutorial so you are just going to download the source code. When you click this button, it will display like this image below: wifi enabled Here's the full code of this tutorial:
  1. Sub Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.
  4. End Sub
  5.  
  6. Sub Globals
  7. 'These global variables will be redeclared each time the activity is created.
  8. 'These variables can only be accessed from this module.
  9. Dim ph As ICOSPhone
  10. Dim btnWifi As Button
  11.  
  12. Dim btnWifiOnOff As Button
  13. End Sub
  14.  
  15. Sub Activity_Create(FirstTime As Boolean)
  16. 'Do not forget to load the layout file created with the visual designer. For example:
  17. Activity.LoadLayout("main")
  18. End Sub
  19. Sub Activity_Resume
  20. End Sub
  21.  
  22. Sub Activity_Pause (UserClosed As Boolean)
  23.  
  24. End Sub
  25.  
  26.  
  27. Sub btnWifi_Click
  28. ph.OpenWifiSettings
  29. End Sub
  30.  
  31. Sub btnWifiOnOff_Click
  32. ph.WiFiOnOff(LoadBitmap(File.DirAssets,"wireless_on.png"),LoadBitmap(File.DirAssets,"wireless_off.png"))
  33. End Sub
Download the source code below and try it! For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

Submitted byctzon Mon, 07/14/2014 - 13:35

Parsing code. Error Error parsing program. Error description: Unknown type: icosphone Are you missing a library reference? Occurred on line: 23 Dim ph As ICOSPhone

Add new comment