[solved]Getting the mac address of my router

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

[solved]Getting the mac address of my router

Postby Pandoro » Sun Dec 06, 2009 10:50 pm


I'm writing an application which determines its place by getting the MAC-Address of the current router it is connected to, then sends this address to a server which will then give the name of the location, found in a database.

The problem I have now is how to get the MAC-address. So far I tried something like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2. WifiInfo wifi;
  4. WifiManager wifiMan = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  6. wifi = wifiMan.getConnectionInfo();
  8. String macAddress = wifi.getMacAddress();
Parsed in 0.031 seconds, using GeSHi

In the emulator this crashes, but I figured that might be normal since WIFI isn't emulated. So I tried using a bootable android version (http://www.android-x86.org/) on my laptop. Same result there. Sadly I don't have a android phone yet, so I can't really test it. And since these classes aren't really well documented I'm not sure if I can just hope this will run, or if I need to look for something else.

So my question is, am I using the right code? Or do I need to find a different solution to my problem.

Thanks in advance,

Okay.... I solved my problem -.- I'm almost ashamed to say what it was, but for anyone else having this problem...

My mistake was it that I did not use the ACCESS_WIFI_INFO permission in my manifest file. After that my app ran fine. Although I'm still curious why the getBSSID() function gives the MAC-Address of the router and not the getMacAddress() function. This returned null.
Junior Developer
Junior Developer
Posts: 12
Joined: Wed Nov 04, 2009 9:41 pm
Location: Netherlands


Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests