在Windows Phone 7中获取IMEI号码

时间:2011-09-15 06:33:25

标签: windows-phone-7 imei

  

可能重复:
  Find IMEI no in wp7?

是否有任何API在Windows Phone 7中获取设备IMEI号码,我可以使用DeviceExtendedProperties.GetValue(“DeviceUniqueId”)获取“设备唯一ID”,但我需要获取IMEI。

1 个答案:

答案 0 :(得分:-2)

CC:HTTP://www.cnblogs.com/xjb/archive/2007/02/05/640360.html

以下代码未经我测试。

public struct GeneralInfo
{
    public string Manufacturer;
    public string Model;
    public string Revision;
    public string SerialNumber;
    public string SubscriberNumber;
}

/// <summary>
/// Tapi control class
/// </summary>
public class ControlTapi
{

    [DllImport("cellcore.dll")]
    private static extern int lineGetGeneralInfo(IntPtr hLigne,byte[]lpLineGeneralInfo );

    /// <summary>
    /// Invoke cellcore.dll to get info of sim
    /// </summary>
    /// <param name="l"></param>
    /// <returns></returns>
    private  GeneralInfo GetGeneralInfo(Line l)
    {
        GeneralInfo lgi = new GeneralInfo();
        byte[] buffer = new byte[512];
        BitConverter.GetBytes(512).CopyTo(buffer, 0);

        if (lineGetGeneralInfo(l.hLine, buffer) != 0)
        {
            throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
        }

        int subscsize = BitConverter.ToInt32(buffer, 44);
        int subscoffset = BitConverter.ToInt32(buffer, 48);
        lgi.SubscriberNumber = System.Text.Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString();
        lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("\0", "");
        return lgi;

    }



    /// <summary>
    /// GET IMSI of SIM Card
    /// </summary>
    /// <returns></returns>
    public static string  GetIMSINumber()
    {
        string result = "";
        try
        {
            Tapi t = new Tapi();
            t.Initialize();
            Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
            ControlTapi ctapi = new ControlTapi();
            GeneralInfo gi = ctapi.GetGeneralInfo(l);

            result =  gi.SubscriberNumber;
            l.Dispose();
            t.Shutdown();

        }
        catch// (Exception ex)
        {
            result = "";
        }

        return result;

    }

    /// <summary>
    /// Get IMEI
    /// </summary>
    /// <returns></returns>
    public static string GetIMEINumber()
    {
        string result = "";
        try
        {
            Tapi t = new Tapi();
            t.Initialize();
            Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
            ControlTapi ctapi = new ControlTapi();
            GeneralInfo gi = ctapi.GetGeneralInfo(l);
            result = gi.SerialNumber;
            l.Dispose();
            t.Shutdown();

        }
        catch// (Exception ex)
        {
            result = "";
        }

        return result;
    }

}