Android Question MAC Address

Peter Yeung

Member
Licensed User
Longtime User
How to get the MAC Address of Android device.

Is it possible for an Android device to have MAC two Addresses? i.e. one for Wifi and one for mobile data?

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Wifi MAC address: https://www.b4x.com/android/forum/t...s-with-serial-on-android-6.60452/#post-420300

This will return the wifi address.

You can change the Java code to:
B4X:
#if JAVA
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.List;
public static String getWifiMacAddress() {
  try {
  String interfaceName = "wlan0";
  List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
  for (NetworkInterface intf : interfaces) {
BA.Log("" + intf);
  byte[] mac = intf.getHardwareAddress();
  if (mac==null){
  continue;
  }

  StringBuilder buf = new StringBuilder();
  for (byte aMac : mac) {
  buf.append(String.format("%02X:", aMac));
  }
  if (buf.length()>0) {
  buf.deleteCharAt(buf.length() - 1);
  }
 
  BA.Log(buf.toString());
  }
  } catch (Exception ex) {
  ex.printStackTrace();
  }
  return "";
  }
#end if
This will print all the found addresses.
 
Upvote 0
Top