Main objective of this tutorial is to help you to get information about the WiFi connections.


You will get Final Output:

Wi-Fi Connection Demo


Step 1 file

First we need Broadcast Receiver for the Wifi state connection information. So Create new class named WiFiScanReceiver.

public class WiFiScanReceiver extends BroadcastReceiver {
    private static final String TAG = "WiFiScanReceiver";
    WiFiDemo wifiDemo;
    public WiFiScanReceiver(WiFiDemo wifiDemo) {
        this.wifiDemo = wifiDemo;
    public void onReceive(Context c, Intent intent) {
        List<ScanResult> results = wifiDemo.wifi.getScanResults();
        ScanResult bestSignal = null;
        for (ScanResult result : results) {
            if (bestSignal == null || WifiManager.compareSignalLevel(bestSignal.level, result.level) < 0)
                bestSignal = result;
        String message = String.format("%s networks found. %s is the strongest.",
        results.size(), bestSignal.SSID);
        Toast.makeText(wifiDemo, message, Toast.LENGTH_LONG).show();
        Log.d(TAG, "onReceive() message: " + message);

Step 2 setWiFiStatus() method

Now we create new method into our Main Activity File called setWiFiStatus(). It is used for set all the status of the different WiFi connections. And also we need register a receiver for WiFi scanning.

//private TextView textStatus;
//textStatus = (TextView) findViewById(;
private void setWiFiStatus() {
    // Setup WiFi
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    // Get WiFi status
    WifiInfo info = wifi.getConnectionInfo();
    textStatus.append("\n\nWiFi Status: " + info.toString());

    // List available networks
    List<WifiConfiguration> configs = wifi.getConfiguredNetworks();
    for (WifiConfiguration config : configs) {
        textStatus.append("\n\n" + config.toString());

    // Register Broadcast Receiver
    if (receiver == null)
        receiver = new WiFiScanReceiver(this);
    registerReceiver(receiver, new IntentFilter(
    Log.d(TAG, "onCreate()");

For More Details visit following links:

I hope you enjoy this tutorial and it would be helpful to you.

Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.

An entrepreneur who has founded 2 flourishing software firms in 7 years, Tejas is keen to understand everything about gaming - from the business dynamics to awesome designs to gamer psychology. As the founder-CEO of a company that has released some very successful games, he knows a thing or two about gaming. He shares his knowledge through blogs and talks that he gets invited to.