Created
September 18, 2018 06:07
-
-
Save TheAlphamerc/5abd7ed8cd284e5b336ce6ef4ebaf3d6 to your computer and use it in GitHub Desktop.
Code to get mac address in xamarin android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, its works.
using Java.Net;
using Java.Util;
using NetworkInterface = Java.Net.NetworkInterface;