Getting IMEI number in windows phone 7 [duplicate]

China☆狼群 提交于 2019-12-12 01:59:41

问题


Possible Duplicate:
Find IMEI no in wp7?

Is there any api that gets the device IMEI number in windows phone 7, all i can get it "device unique id" by using DeviceExtendedProperties.GetValue("DeviceUniqueId"), but i need to get IMEI.


回答1:


cc:http://www.cnblogs.com/xjb/archive/2007/02/05/640360.html

the following code is not tested by me.

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;
    }

}


来源:https://stackoverflow.com/questions/7426757/getting-imei-number-in-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!