Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

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

import android.util.Log;

public class Main {
    private static final String TAG = "CommonUtils";

    public static String getWifiName(Context context) {
        Log.v(TAG, "-- Calling WIFI NAME --");
        if (context != null) {
            ConnectivityManager conMgr = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) {
                WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
                Log.v(TAG, "-- WIFI is Enabled Name = " + wifiInfo.getSSID());
                return wifiInfo.getSSID();
            }
        }
        return "";
    }
}