Making Android App with Xamarin 2 – Get InsntaceID

Continue on from the previous article on Making Android App with Xamarin 1 – Splash Screen.  Let’s now make sure the device has valid credential, and if not ask user to input their login information.

Since TWC handles sensitive personal information I want to make sure the app is secured.  So there will be two way authentication to manage credential and devices.

There are two things that can happen, when they launch the app.

  1. The user is already a member, already registered via web service.
  2. The user is new want to register as a member.

If the case, user is a member, then;

First get device ID and see if it is valid to move forward.

If valid then move forward to the main Activity, if not, then get ready link that device ID and credential information.

My memo on how login should be designed.

  • From the web service, user should be able to unlink the device. In case they loose their phones etc.
  • Even after the device is linked with valid credential, user should be able to protect the use of app with pass code. (and may be more authentication method).
  • If the credential information is changed at web service, aka changed password, the link between the device should be removed.
  • I want to let user know that new device is linked, just to make sure that is the action they want, and also let them know how they can unlink the device if they want.

Let’s start off from the baby step 1, Get device ID.

First I am reading Best Practices for Unique Identifiers, since the title seems like right article to read first. In short it said;

  • Avoid using hardware ID
  • Only use Adverting ID for user profiling or ads use-cases
  • Use and Instance ID or privately stored GUID whenever possible for all other use-cases except payment fraud prevention and telephony.
  • Use API that are appropriate to your use-case to minimize privacy risk.

It sounds like storing private GUID at time of installation sounds like the best thing to do.  If I read correct, Instance ID is generated at time of installation and live as long the app is installed.

In this case, if user uninstall the app and re-install, the ID changes but other wise stays same.  Detail of Instance ID can be found here.

From Nuget, get Xamarin.GooglePlayService.Gcm first then;



Then at SplashActivity.cs, let’s get Instance ID show on Debug Output.



OK, great we got ID.

Let’s next tie this ID with Credential that is used on regular web service.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.