110,538
社区成员
发帖
与我相关
我的任务
分享
string deviceid = TelephonyManager.FromContext(inflater.Context).DeviceId;
/// <summary>
/// Retrieve the IMEI from the TelephonyManager
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static string GetDeviceId(Context context)
{
TelephonyManager telephonyMgr =
context.GetSystemService(Context.TelephonyService) as TelephonyManager;
string deviceId = telephonyMgr.DeviceId == null ? "UNAVAILABLE"
: telephonyMgr.DeviceId;
return deviceId;
}
/// <summary>
/// Retrieve the PhoneNumber from the TelephonyManager
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static string GetPhoneNumber(Context context)
{
TelephonyManager telephonyMgr =
context.GetSystemService(Context.TelephonyService) as TelephonyManager;
string phoneNumber = telephonyMgr.Line1Number == null ?
"UNAVAILABLE" : telephonyMgr.Line1Number;
return phoneNumber;
}