[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

Hello,

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
  1.  
  2. WifiInfo wifi;
  3.  
  4. WifiManager wifiMan = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  5.  
  6. wifi = wifiMan.getConnectionInfo();
  7.  
  8. String macAddress = wifi.getMacAddress();
  9.  
  10.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


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,
pandoro


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.
Pandoro
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Nov 04, 2009 9:41 pm
Location: Netherlands

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests