Ionic 4 | Get Unique Device ID & Other Uid’s of UUID, IMEI, IMSI, ICCID and MAC using Native & Cordova Plugins

A device may have a different type of ID’s stored in it which are of different type and have different significance. Each device has this type of ID’s but in unique and distinct values. These ID’s can be a Unique Device ID, IMEI Sim number, MAC Address, etc.

As a developer, we may need such ID’s to save user data distinctly or for other purposes. In this post, we will talk about Two Ionic Native plugins which are specialized to fetch some of the important ID from a user device.

Unique Device ID: This plugin produces a unique, cross-install, app-specific device id.

Uid: Get unique identifiers: UUID, IMEI, IMSI, ICCID and MAC.

Let’s start with a new Ionic 4 Application

Update Ionic CLI

Make sure you have the latest version on Ionic CLI installed (current is v5.0.0)

Create a new Ionic 4 Application

To demonstrate we will create a new Ionic 4 application with a blank template, but if you already having an application up and running just go for it.

As our application is ready, let’s install two plugins to fetch Ids from a real device.

Install Unique Device ID Native & Cordova Plugin

Unique Device ID native plugin helps to fetch a unique device ID for Android, iOS and Windows Phone 8 which will remain the same even if the application is uninstalled by the user.

For cordova, we used this package instead of this show in Ionic’s native plugin page due to some bugs.

Install Uid Native & Cordova Plugin

Uid plugin will allow getting details about ID’s related to UUID, IMEI, IMSI, ICCID and MAC

for this plugin, we need Android Permissions plugin to get READ_PHONE_STATE permission

 

Import plugins in App’s Module

To use these plugins globally we will import then add in imports array in the app.module.ts file as shown below

Get ID’s in Home Component

To use in a component like home which is created by default in a blank Ionic template, first import plugins then add them in the constructor.

Let’s add Unique Device ID, Uid and Android Permissions plugin in home.page.ts file

Get Unique Device ID

To get Unique Device ID just call a get() method of uniqueDeviceId service

Get UUID, IMEI, IMSI, ICCID, and MAC using Uid Service

To use this plugin service method we need to check if application having READ_PHONE_STATE permission by calling getPermission() method in constructor.

After that, we only need to call uid variables to get values like

The complete home.page.ts file after adding all methods will look like this

That’s it! so here we discuss two Ionic Native plugins to get some of the important ID’s in Ionic application.

Thanks for visiting :) Let me know if you have some suggestions or feedback for this post in the comment section. Looking for any tutorial or demo on FreakyJolly, just drop me a message here

4
Leave a Reply

avatar
2 Comment threads
2 Thread replies
4 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
anRoswellDavidAle del RíoJoshua Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Joshua
Guest
Joshua

is it possible to retrieve the IMEI without restarting the application?

David
Guest
David

I’m interested too

anRoswell
Guest
anRoswell

i have the same question

Ale del Río
Guest
Ale del Río

This tutorial is amazing. Thank you very much!