0

How to get the mac address in the absence of the wifi!! and am using the following code to get the mac address in the presence of the wifi `public static String getMACaddress(Context ctx) {

            WifiManager wifiManager = (WifiManager)ctx.getSystemService(Context.WIFI_SERVICE);

            if (wifiManager.isWifiEnabled()) 
            {
            WifiInfo wInfo = wifiManager.getConnectionInfo();
            String macAddress = wInfo.getMacAddress(); 
            }
        `

in the else part i want to get the mac address in the normal way i mean without the internet connection.

Madhan Devan
  • 147
  • 3
  • 10

1 Answers1

1

See the below post.. In this without using of wifi connection getting mac address.may it will help you.

// AndroidManifest.xml permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

// test functions
Utils.getMACAddress("wlan0");
Utils.getMACAddress("eth0");
Utils.getIPAddress(true); // IPv4
Utils.getIPAddress(false); // IPv6 

How to get IP address of the device from code?

Community
  • 1
  • 1
Anjali Tripathi
  • 1,477
  • 9
  • 28
  • @Tripathi fine thank you !!! but i want to pass the address as the string and i have to dispaly in the textview but in the above how can i pass ? please can you give a brief ?? and also also they have given the two different adress What it mean of "wlan0" and "eth0" ? – Madhan Devan Feb 24 '14 at 06:11
  • the return type of method getIPAddress() is string so you can store it string and then show in your textview.. – Anjali Tripathi Feb 24 '14 at 06:19
  • Utils.getMACAddress("wlan0"); Utils.getMACAddress("eth0"); not working retun null – Kanaiya Katarmal Feb 24 '14 at 08:18