You can use the lib YES of ionic-native
.
Example:
getInformacoesSIM() {
this.sim.requestReadPermission().then(() => {
this.sim.getSimInfo().then((info) => {
console.log(info);
}, err => {
console.log(err);
})
}, () => console.log('Permission denied'))
}
If you prefer to avoid the chaining of your files, you can also use the async/await
async getInformacoesSIM() {
try {
let permission = await this.sim.requestReadPermission();
let info = await this.sim.getSimInfo();
console.log(info);
} catch (er) {
console.log(er);
}
}
According to the documentation, in return you will have the following payload
:
{
"carrierName": "Android",
"countryCode": "us",
"mcc": "310",
"mnc": "260",
"phoneNumber": "15555215554",
"deviceId": "0000000000000000",
"simSerialNumber": "89014103211118510720",
"subscriberId": "310260000000000",
"callState": 0,
"dataActivity": 0,
"networkType": 3,
"phoneType": 1,
"simState": 5,
"isNetworkRoaming": false
}
NOTE: the content of phoneNumber is unreliable (see this and this
article). Sometimes phoneNumber is only an Empty string.
According to the README.txt
lib, not all phones are "able" to return the phone number, in which case the phoneNumber will be represented by an empty string.
I was trying exactly like this, but on my smartphone I was returning empty. So I thought I was doing something wrong. When I debugged, then I realized what was actually returning. Vlw to answer. = D
– viana