How to get Device Unique ID

#1

Can any one tell how to get device id (unique id)?

#2
ionic install cordova-plugin-device --save

In your TS:

import {Device} from 'ionic-native';
import {Platform} from 'ionic-angular'; //for detect OS

When you need to use it:

declare var device: any;

    constructor(private platform: Platform) {
        //uuid
        console.log(device.uuid); 
        
        //os and version
        let system = this.platform.is('ios') ? 'ios' : (this.platform.is('android') ? 'android' : 'windows');
        console.log(system + '@ ' + device.version);
    }
3 Likes
#3

Dear @twicejr,

When I try the command

ionic install cordova-plugin-device --save

I got

[ERROR] Unable to find command: install cordova-plugin-device

please advise

#4

to install Cordova plugins, use: cordova plugin add cordova-plugin-device

Plugin info: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/

2 Likes
#5

It should be npm install …, I suppose…

#6

Hi @htbill,@twicejr

I have now problem of

[ts] Cannot find module ‘ionic-native’.

as shown in import section

specfc

Please advise how to fix it

N.B I am using ionic 3…

Thanks

Anes

#7
#8

This is not compatible with ionic 3.
You should fork this plugin or look for another alternative.

See upgrade guide from Ionic 2>3 and apply these changes, if you are
able to do it.
I got no time for this right now.

#9

Dear @htbill

I got Runtime error as ERROR Error: Uncaught (in promise): Error: No provider for Device!

Please advise

Thanks

#10