get Wifi Ap SSID - Android Wifi

Android examples for Wifi:Wifi SSID

Description

get Wifi Ap SSID

Demo Code


//package com.java2s;

import android.net.wifi.WifiConfiguration;

import android.net.wifi.WifiManager;
import java.lang.reflect.Field;

import java.lang.reflect.Method;

public class Main {
    private static WifiManager mWifiManager;

    public static String getApSSID() {
        try {/*w ww .  j  a v a 2 s.  co m*/
            Method localMethod = mWifiManager.getClass().getDeclaredMethod(
                    "getWifiApConfiguration", new Class[0]);
            if (localMethod == null)
                return null;
            Object localObject1 = localMethod.invoke(mWifiManager,
                    new Object[0]);
            if (localObject1 == null)
                return null;
            WifiConfiguration localWifiConfiguration = (WifiConfiguration) localObject1;
            if (localWifiConfiguration.SSID != null)
                return localWifiConfiguration.SSID;
            Field localField1 = WifiConfiguration.class
                    .getDeclaredField("mWifiApProfile");
            if (localField1 == null)
                return null;
            localField1.setAccessible(true);
            Object localObject2 = localField1.get(localWifiConfiguration);
            localField1.setAccessible(false);
            if (localObject2 == null)
                return null;
            Field localField2 = localObject2.getClass().getDeclaredField(
                    "SSID");
            localField2.setAccessible(true);
            Object localObject3 = localField2.get(localObject2);
            if (localObject3 == null)
                return null;
            localField2.setAccessible(false);
            String str = (String) localObject3;
            return str;
        } catch (Exception localException) {
        }
        return null;
    }
}

Related Tutorials