is wifi Changed SSID - Android Wifi

Android examples for Wifi:Wifi SSID

Description

is wifi Changed SSID

Demo Code

/*/*from ww  w .  j  a  va2 s  .  co m*/
 WiFiUtil.java
 Copyright (c) 2014 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */
//package com.java2s;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class Main {

    public static boolean isChangedSSID(final Context context,
            final String oldSSID) {
        String current = getCurrentSSID(context);
        if (current == null) {
            return (oldSSID != null);
        }
        return !current.equals(oldSSID);
    }

    public static String getCurrentSSID(final Context context) {

        String ssid = null;

        if (isOnWiFi(context)) {
            WifiManager wifi = (WifiManager) context
                    .getSystemService(android.content.Context.WIFI_SERVICE);
            ssid = wifi.getConnectionInfo().getSSID();

            if (ssid != null) {
                ssid = ssid.replaceAll("\"", "");
            }
        }

        return ssid;
    }

    public static boolean isOnWiFi(final Context context) {

        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();

        if (ni == null || !ni.isConnected()
                || (ni.getType() != ConnectivityManager.TYPE_WIFI)) {
            return false;
        }

        return true;
    }
}

Related Tutorials