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.
Asked
Active
Viewed 6,489 times
1

Suyash
- 365
- 5
- 18

yogesh narhare
- 13
- 1
- 5
1 Answers
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
-
I need same for iOS as well. – yogesh narhare May 30 '18 at 10:33
-
Thanks. I will get it myself. – yogesh narhare May 30 '18 at 10:40
-
1We cannot get IMEI of an Apple device, Apple doesn't allow us. Look [here](https://stackoverflow.com/a/19927376/5941852) – VahidShir May 30 '18 at 10:59
-
Waht you import to use Settings.Secure ? – Krzysztof Pokrywka Jul 24 '18 at 06:54
-
1@KrzysztofPokrywka use "using Android.Provider;" – Lucas Riechelmann Ramos Sep 28 '18 at 17:30