Make a Wifi Scanner in Sketchware Pro

 Hi, hope you are ok

You must be here because you searched for how to make a wifi scanner application from Google or maybe you saw the post on my youtube video (https://youtu.be/RkyJqO1IJXI), anyways it doesn't matter because you're already here.

And so i will take the chance to explain to you the concept of making a wifi scanner in sketchware pro.

First you need to do a few things that i will explain in this post.



1: Build a Project and add the following..

 To your new project, add a listview and a button.


• The Listview there will get all the names of the Wifi networks or users that are around you.

• Under the Listview, the button will be used to scan for the Wifi and then put all of them in the Listview. You can name then button anything you would like but i suggest 'scan' because that's what it does...to scan...


2: Create a Moreblock to add a Class

   Yes, as an old method of adding classes in sketchware, Moreblocks are used to add class codes in projects.

We will use this method for the same reason.

Create a moreblock then name it anything, no need to add variables in it. 

When you are done, Paste this code in the moreblock using asd block


}

class WifiReceiver extends BroadcastReceiver {

        public void onReceive(Context c, Intent intent) {

}


Once you are done, let's go to part 3


3: Create another Moreblock (name it 'setAdapter')

   As the name is suggesting, we are going to add a list adapter code to manage the Wifi list that will be received once scanning is done.

Again, this Moreblock does not need additional variables, but just the code in it will be different...


  adapter = new ListAdapter(getApplicationContext(), wifiList);

         lvWifiDetails.setAdapter(adapter);


_IvWifiDetails is the listmap that gets all the Wifi networks or connections to the listview


4: Just Create one last Moreblock, then name it 'scanWifiList'

   This is the most important of the three Moreblocks because it is responsible for scanning all Wifi connections or networks around you. Don't ignore it, it's the brain and professor to the Project.

To be able to scan and make the Moreblock useful, paste this code in it in an asd block..


mainWifi.startScan();

wifiList = mainWifi.getScanResults();


The 'startScan' command will scan the Wifi connections for you. Of course, this is what programming is all about right? 


After adding the scan code, click moreblocks and drag the adapter block below the block.

Ok now it's time to get away from Moreblocks and get to something else. This time we will go to Oncreate on Part 5 and... Just follow up below... 


5: Time For Oncreate

  You all know the Oncreate event right? The one that executes when the app starts? Ok ok.. 

In here you will add a code to create a WifiManager(); variable that was used in the Moreblocks above and then use it to start a Scan Service once the app is opened.

Here is the code ;


lvWifiDetails = (ListView) findViewById(R.id.listview1);

mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

receiverWifi = new WifiReceiver();

registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));


Ok, the code above needs a permission from your device to actually scan the Wifi connections around your area. If you are currently using Sketchware Pro, you can directly add the permission by going to permissions - then adding the permission (Access_fine_location).

To find this permission faster, use the

search bar provided


If you are using the original version of Sketchware though, you need to add the permission using a code. The code will check your Build.sdk version and then display a permission dialog for you to accept.

The code ;


if (Build.VERSION.SDK_INT >= 23) {

    if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {

      requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 1000);

    }


6 : Adding Imports

  Yes, the imports are for all the variables that we have added above, in the Moreblocks and at Oncreate event.

Add these imports but make sure android.manifest is last.


android.content.IntentFilter

android.net.wifi.ScanResult

android.content.pm.PackageManager

android.net.wifi.WifiManager

android.Manifest



7: Onclick Event (the last step);

  On the button that we added above, we will add an onclick event to it, I mean execute instructions once it is clicked.

Click the button - event - then onclick to create it. In there, add the Moreblock 'scanWifiList' that will scan for Wifi connections that your device will be able to pick.

That is it. You can now compile the project and create an application that can scan for Wifi even Free WiFi.


You can Subscribe to my Channel on Youtube

Duoedge Studios

GoodLuck (~‾▿‾)~.

1 comment:

  1. How can I open my link in both app and website? I am using intent filter but it only open in app not in website it shows webpage doesn't exist

    ReplyDelete

Note: Only a member of this blog may post a comment.

Powered by Blogger.