1

I had add references Plugin.DeviceInfo in project and used CrossDevice.Device.DeviceId for get IMEI no in code but it throws exception "The type initializer for plugin.DeviceInfo.CrossDevice threw an exception"`. How to resolve this.

Suyash
  • 365
  • 5
  • 18

1 Answers1

3

Try this:

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

And then

string deviceIdentifier = DependencyService.Get<IDevice>().GetIdentifier();
MMachado
  • 88
  • 10