Monday, December 22, 2014

Read DeviceId in Xamarin Android

Q : How to read Device-id in Xamarin Android?

Ans:

Some times we want to read Device-id while developing the app's.
this code will help you to read the device-id in Xamarin Android.
i use the below code to read the device-id in my app.
  1. Create a Xamarin Android project.
  2. Right click on your project -> properties -> Android Mainfest.
  3. it will display as below.
  4. select the READ_PHONE_STATE option.
  5. then go to your activity page.
  6. add the line"using Android.Telephony;".
  7. you can write the code in OnCreate method.
         TelephonyManager tM = (TelephonyManager)GetSystemService(Context.TelephonyService);
         String uid = tM.DeviceId;

you can read the device-id like this.

2 comments: