How to get device details

Hi,
I was wondering how to get devicePlatform, deviceId, deviceVersion and deviceModel in ionic2, any code or any lead will be appreciated. Found a link in ionic v2 documentation but it leads to 404!

1 Like

you can use this

https://github.com/apache/cordova-plugin-device

No need to import anything. Just use directly like

class MyPage
{
    constructor(){ ... }
    
    getDeviceDetails(){
      var model = device.model;
      var deviceID = device.uuid;
      var string = device.version; 
   }
}
1 Like

@mrameezraja, I am geeting a error msg saying device not defined. Which version of ionic you are using?

1 Like

ionic2. Have you installed device plugin ?

C:\ionic\test>ls plugins
android.json cordova-plugin-device cordova-plugin-statusbar fetch.json
cordova-plugin-console cordova-plugin-splashscreen cordova-plugin-whitelist ionic-plugin-keyboard

I have it installed

@mhartington, I am having issues finding device details, can you suggest me something here?

You need to check if platform is ready, then use it.

constructor(platform: Platform) {
    platform.ready().then(() => {
                console.log(device.uuid);
            });

}
2 Likes

Can u suggest how to get the serial number of the device? except it i can fetch details of other device details using Device.device.uuid etc,

1 Like

You can’t get serial number programmatically.

how about getting ip address of a device ? i tried to import network interface plugin,but i am able to import network information plugin alone

r u getting any solution for fetch device detail.
because i also get same msg …device not found

I think now ionic-native is having Device listed, you can refer the same
for solution.

i tried Device.model but get error model not found

Try Device.device.model; this should work.

import {Device} from 'ionic-native';

platform.ready().then(() => {
   console.log(Device.device.uuid);
}

This gives me {}, a blank object.

If you have a latest ionic-native then you may need to use it as
console.log(Device.uuid);
There are some changes in latest ionic-native

1 Like

hi @maruti how do u check whether u have installed the plug?
i remember the plug device was include in rc 4.0. u can see in package.json. and i do it as the above the chrome give me a warning as below:

main.js:205 Native: tried calling Device.uuid, but the Device plugin is not installed.
pluginWarn @ main.js:205
main.js:210 Install the Device plugin: ‘ionic plugin add cordova-plugin-device’

i try to run this command." ionic plugin add cordova-plugin-device" no effect. the still happens.
anyone encounter this situation? can give a way to resolve this?

hi @samarthagarwal did u solve this ?

Yes, I just updated my **ionic-native** module by modifying my package.json file and then doing an npm install.

So, make sure that your package.json file has"ionic-native": "^2.2.11". Notice the version, it is very important. The issue is fixed in this particular version. After that, save the file and do an npm install. Then simple use it as Device.uuid. It works.