How to identify first time App installation and device id in ionic3

Identify first time App initialisation:

Here we learn “How to identify first time App installation and device id in ionic3“, in this article we find the device id and identify the first time app initialisation.

There is lot’s of benefit for getting device id at the time of app installation.

Output Example –

How to identify first time App initialisation or find device id within any app in ionic3

Follow these steps for getting the device id of app –

Step 1: 

First we need to install and add plugin.

ionic cordov plugin add cordova -plugin-device 
npm install --save @ionic-native/device

Step 2:

Now we import and add it into providers .

import { Device } from '@ionic-n tive/device';

providers: [ 
  {provide: ErrorHandler, useClass: IonicErrorHandler}, Device
]

Step 3:

Now we identify the device id or first installation of app in any device, so we put the code to app initialization. Goto the app.component.ts file, beacause this is a first time runing file.

import { Device } from '@ionic-native/device';
 
constructor(private device: Device) {}

//These are the following information which we get from device.
 
DeviceInformation()
{ 
console.log('Device UUID is: ' + this.device.uuid); 
console.log('Get the device hardware serial number: ' + this.device.serial);
console.log('Device Name: ' + this.device.n me);
console.log('Device manufacturer is: ' + this.device.manufacturer);
console.log('Whether the device is running on simulator: ' + this.device.isVirtual);
console.log('Device oper ting system version is: ' + this.device.version);
console.log('Device operating system name is: ' + this.device.platform);
console.log('N me of the deviceʼs model or product is: ' + this.device.model);
console.log('Device cordov version is: ' + this.device.cordov );
}
 
public checkAppInstallation( appInstallCheck)
{
  this.storage.set('installFirsttime', appInstallCheck);
  if(appInstallCheck == true){ 
   let alert = this. alertCtrl.create({ 
   title: 'App Installed!', message: 'Your App is inst lled now', 
   buttons:[{ text: 'Ok', role: 'ok', handler: () => { 
   this.navCtrl.setRoot(MainPage); } }] });
    alert.present();
} 

public checkAppInstallation(appInstall){ 
 if(!appInstall){ 
   this.storage.set('installFirsttime', true); 
   let alert = this. alertCtrl.create({
   title: 'App Installed And Device Information!', 
   message: '<b>Device UUID is:</b> ' + this.device.uuid + '<br><br>
   <b>Device h rdw re seri l number:</b> ' + this.device.seri l + 
  '<br><br><b>Device manufacturer is:</b> ' + this.device.manufacturer 
  + '<br><br><b>Device is running on simulator:</b> ' + 
  this.device.isVirtual + '<br><br><b>Device oper ting system version 
  is:</b> ' + this.device.version + '<br><br><b>Device operating 
  system name is:</b> ' + this.device.platform + '<br> <br><b>Name of 
  the deviceʼs model or product is:</b> ' + this.device.model + 
  '<br><br><b>Device cordova version is:</b> ' + this.device.cordova , 
  buttons: [{ text: 'Ok', role: 'ok', handler: () => { 
  this.nav.setRoot(ActivationPage); } }] });
  alert.present();
} 

So finally we able to identify the first time app installation or some of other device information. That’s it. 

Why i choose ionic –

I’m a big fan of ionic with angular, because it is very easy to implement complicated concepts and designs, in above example i am explain you in detail how to create a very simple way to identify the app id and first time app installation.

So we complete the tutorial which is “How to identify first time App installation and device id in ionic3“.

You can find my post on medium as well click here please follow me on medium as well.

You can find my next post here.

If have any query/issue, please feel free to ask.

Happy Coding Guys.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *