I found the following code on the internet which purportedly allows access to the MAC address on Android 6.
I've tried to embed it into my code but it fails.
It says:
any suggestions would be appreciated.
Rusty
I've tried to embed it into my code but it fails.
B4X:
#if java
public static String getMacAddr() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) continue;
byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
return "";
}
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(Integer.toHexString(b & 0xFF) + ":");
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
}
return "02:00:00:00:00:00";
}
#end if
Sub GetMAC As String
NativeMe.InitializeContext
Dim s As String = NativeMe.RunMethod("GetMacAddr", Null)
Return s
End Sub
It says:
error: cannot find symbol
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
any suggestions would be appreciated.
Rusty