0

I'm trying to get MAC addres of Wifi network of Eclipse android emulator with this:

WifiManager wifiManager = (WifiManager) LoginActivity.this.getSystemService(WIFI_SERVICE);
            WifiInfo wInfo = wifiManager.getConnectionInfo();
            String macAddress = wInfo.getMacAddress(); 
            System.out.println("HI");
            System.out.println(macAddress);

This is the android manifest permissions

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

When the execution arrives to

System.out.println(macAddress);

The app crashes with java nullpointerexception and close it.

What are doing wrong? I have to add wifi conectivity to emulator?

Hanzo
  • 1,839
  • 4
  • 30
  • 51
  • you can not use wify connection with emulator [link](http://stackoverflow.com/questions/7876302/enabling-wifi-on-android-emulator) – Imtiyaz Khalani Jan 15 '14 at 09:17

1 Answers1

2

The doc about WifiManager.getConnectionInfo() states that it :

Return dynamic information about the current Wi-Fi connection, if any is active.

This means that in this case, you'd want to check whether your WifiInfo is not null and that your device is effectively connected to a Wi-Fi network. In the case of the emulator, the MAC address is always null, so you should make sure what you're outputting is valid.

Halim Qarroum
  • 13,985
  • 4
  • 46
  • 71