Skip to content

Instantly share code, notes, and snippets.

@TheAlphamerc
Created September 18, 2018 06:07
Show Gist options
  • Save TheAlphamerc/5abd7ed8cd284e5b336ce6ef4ebaf3d6 to your computer and use it in GitHub Desktop.
Save TheAlphamerc/5abd7ed8cd284e5b336ce6ef4ebaf3d6 to your computer and use it in GitHub Desktop.
Code to get mac address in xamarin android
using Java.Net;
using Java.Util;
namespace Helpers
{
public class AndroidDevice
{
/// <summary>
/// Code to get mac address in xamarin android
/// </summary>
/// <returns>The <see cref="string"/></returns>
public string GetMacAddress()
{
var s = "";
var all = Collections.List(NetworkInterface.NetworkInterfaces);
foreach (var inter in all)
{
var mac = (inter as NetworkInterface).GetHardwareAddress();
if (mac == null) continue;
var sb = new Java.Lang.StringBuilder();
foreach (var b in mac)
{
sb.Append((b & 0xFF).ToString("X2") + "");
}
s = sb.ToString();
}
return s;
}
}
}
@Julioclm
Copy link

Julioclm commented Apr 22, 2019

Thank you, its works.

using Java.Net;
using Java.Util;
using NetworkInterface = Java.Net.NetworkInterface;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment