xamarin - How do I get the Mac Address for and Android Device using 6.0 or higher in c#? -
i have found few examples using java, having trouble constructing method c#. can please post straightforward c# example gets mac address of device, marshmallow (6.0). understand there other methods of obtaining unique id, not interested in having import components @ time. using xamarin visual studio 2015.
i have these permissions active:
access_wifi_state internet read_phone_state
the codes have tried simple methods used below android version 6.0. appreciated.
edit: i not believe duplicate requested c# version of code specifically
unfortunately, you're out of luck. starting version 6.0, android restricts access mac address. if try query mac address of current device, you'll constant value of 02:00:00:00:00:00
you can still access mac addresses of nearby devices, stated in official android documentation:
to access hardware identifiers of nearby external devices via bluetooth , wi-fi scans, app must have access_fine_location or access_coarse_location permissions:
edit: while official way of getting mac address not supported, sure seems possible taking little detour. post here minimal example goes through network interfaces , outputs mac addresses console if there's one:
// networkinterface java.net namespace, not system.net var = collections.list(networkinterface.networkinterfaces); foreach (var interface in all) { var macbytes = (interface networkinterface).gethardwareaddress(); if (macbytes == null) continue; var sb = new stringbuilder(); foreach (var b in macbytes) { sb.append((b & 0xff).tostring("x2") + ":"); } console.writeline(sb.tostring().remove(sb.length - 1)); }
to use in real world scenario requires null reference checking , other modifications, works.
Comments
Post a Comment