I am trying to obtain the imei of an android device in ionic 2, but so far no luck.
In ionic 1 l just used an ngCordova plugin like cordova-uid https://github.com/hygieiasoft/cordova-plugin-uid.
Is there a plugin for ionic-native that I can use to obtain the imei or is there any other way to get the imei.
Can use this code.
cordova plugin add org.hygieiasoft.cordova.uid
Or
cordova plugin add https://github.com/hygieiasoft/cordova-plugin-uid
For test use console.log
declare var cordova: any;
export class MyApp {
constructor(platform: Platform ) {
platform.ready().then(() => {
console.log(cordova.plugins.uid.IMEI);
});
}
the deviceId in the response is the same as imei. you can do the following
Sim.getSimInfo().then(
(info) => { console.log('Sim info: ', info);
// the line below give you the imei number
console.log(info.deviceId)
},
(err) => console.log('Unable to get sim info: ', err)
);
Sim.hasReadPermission().then(
(info) => console.log('Has permission:', info)
);
Sim.requestReadPermission().then(
() => console.log('Permission granted'),
() => console.log('Permission denied')
);
Check this link https://www.npmjs.com/package/cordova-plugin-sim
Install plugin via
cordova plugin add cordova-plugin-sim
use code
import { Sim } from 'ionic-native';
Sim.getSimInfo().then(
(info) => console.log('Sim info: ', info),
(err) => console.log('Unable to get sim info: ', err)
);
Sim.hasReadPermission().then(
(info) => console.log('Has permission:', info)
);
Sim.requestReadPermission().then(
() => console.log('Permission granted'),
() => console.log('Permission denied')
);