is Current Wifi Connection - Android Phone

Android examples for Phone:wifi

Description

is Current Wifi Connection

Demo Code


//package com.java2s;
import android.content.Context;

import android.net.wifi.ScanResult;

import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

public class Main {
    public static boolean isCurrentWifiConnection(Context c,
            ScanResult result) {//  ww w  .j  av a2s.co  m
        WifiInfo info = getWiFiInfo(c);
        return quote(result.SSID).equals(info.getSSID());
    }

    /**
     *
     * @param c
     * @return Get current connection info
     */
    public static WifiInfo getWiFiInfo(Context c) {
        WifiManager wifiManager = getWifiManger(c);
        return wifiManager.getConnectionInfo();
    }

    private static String quote(String string) {
        return String.format("\"%s\"", string);
    }

    private static WifiManager getWifiManger(Context c) {
        return (WifiManager) c.getSystemService(c.WIFI_SERVICE);
    }
}

Related Tutorials