Skip to content Skip to sidebar Skip to footer

Phonegap Getting Sim Information Using Cordova-plugin-sim

I'm new to mobile development. I'm using PhoneGap and I want to add a feature in my app to get the phone number from the SIM card, both on iOS and Android. I'm using this plugin: c

Solution 1:

Are you testing on iOS or Android? On Android 6.0 and above you need to implement.

window.plugins.sim.requestReadPermission(successCallback, errorCallback);

Also looking at your code. In the errorCallback function, result will be undefined.

You need to change this.

functionerrorCallback(error) {
        document.getElementById("simInfo").innerHTML=JSON.stringify(result);
    }

To this

functionerrorCallback(error) {
        document.getElementById("simInfo").innerHTML=JSON.stringify(error);
    }

Solution 2:

I found this ::

Notice: the content of phoneNumber is unreliable (see this, this, and this article). Sometimes phoneNumber is only an empty string.

I did some changes in code but I got "undefined" message.

<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>SIM</title><scripttype="text/javascript"src="cordova.js"></script><scripttype="text/javascript">document.addEventListener("deviceready",onDeviceReady,false);
            functiononDeviceReady(){
                window.plugins.sim.getSimInfo(successCallback, errorCallback);
            }
            functionsuccessCallback(result) {
                document.getElementById("simInfo").innerHTML=JSON.stringify(result);
                document.getElementById("phone").innerHTML=JSON.stringify(result.phoneNumber);
                document.getElementById("carrierName").innerHTML=JSON.stringify(result.carrierName);
            }
            functionerrorCallback(error) {
                document.getElementById("simInfo").innerHTML=JSON.stringify(error);
            }
        </script></head><body>
        SimInfo :: <pid="simInfo"></p><br />
        Phone Number :: <pid="phone"></p><br />
        Carrier Name :: <pid="carrierName"></p><br /></body></html>

I attached the result image please check this.

enter image description here

please check this. Thanks.

Solution 3:

It gets numbers saved by user as phone number of the sim. If nothing is saved, it will be empty string. I am using redmi note 3. It is there in settings->sim cards & mobile networks->sim1/2->Edit sim card number

Post a Comment for "Phonegap Getting Sim Information Using Cordova-plugin-sim"