I know this question is several years old now, but I wanted to post an updated version, especially for those who may be using Xamarin. This is a solution for C# Xamarin Android, based on the solution posted above by user flawyte.
Here is the code:
public static string GetDeviceSerialCode ( )
{
string serial_number = string.Empty;
try
{
var c = Java.Lang.Class.ForName("android.os.SystemProperties");
var get = c.GetMethod("get", Java.Lang.Class.FromType(typeof(Java.Lang.String)));
serial_number = (string)get.Invoke(c, "gsm.sn1");
if (string.IsNullOrEmpty(serial_number))
{
serial_number = (string)get.Invoke(c, "ril.serialnumber");
}
if (string.IsNullOrEmpty(serial_number))
{
serial_number = (string)get.Invoke(c, "ro.serialno");
}
if (string.IsNullOrEmpty(serial_number))
{
serial_number = (string)get.Invoke(c, "sys.serialnumber");
}
if (string.IsNullOrEmpty(serial_number))
{
serial_number = Build.GetSerial();
}
}
catch (Exception e)
{
serial_number = string.Empty;
}
return serial_number;
}
Lenovo S660
running on4.4.2
and it returns correct value. What device or version you are using? – Learned