How to get device details


#1

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!


#2

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; 
   }
}

#3

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


#4

ionic2. Have you installed device plugin ?


#5

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


#6

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


#8

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

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

}

#9

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,


#10

You can’t get serial number programmatically.


#11

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


#12

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


#13

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


#14

i tried Device.model but get error model not found


#15

Try Device.device.model; this should work.


#16
import {Device} from 'ionic-native';

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

#17

This gives me {}, a blank object.


#18

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


#19

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?


#20

hi @samarthagarwal did u solve this ?


#21

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.