如何从设备获取IMEI否



我在项目中Plugin.DeviceInfo添加了引用,并使用CrossDevice.Device.DeviceId在代码中获取IMEI,但它抛出异常"plugin.DeviceInfo.CrossDevice的类型初始值设定项抛出了异常"。 如何解决这个问题。

试试这个:

[assembly: Xamarin.Forms.Dependency(typeof(UniqueIdAndroid))]
namespace UniqueId.Droid
{
public class UniqueIdAndroid : IDevice
{
public string GetIdentifier()
{
return Settings.Secure.GetString(Forms.Context.ContentResolver, Settings.Secure.AndroidId);
}
}
}

然后

string deviceIdentifier = DependencyService.Get<IDevice>().GetIdentifier();

最新更新