Cordova / Phonegap get phone number of device (Android & iOS)

后端 未结 2 577
时光说笑
时光说笑 2021-01-01 05:18

Is it possible to develop a hybrid mobile app using Phonegap / Cordova and access the device phone number for both Android and iOS?

2条回答
  •  一整个雨季
    2021-01-01 06:05

    Android:I know i am late. After Searching a lot i found this plugin which works for me perfectly... add these plugin in your project

    Put these code in your index.js here

     $(document).ready(function () {
        document.addEventListener("deviceready", onDeviceReady, false);
     });
    
    function onDeviceReady() {
        window.plugins.phonenumber.get(success, failed);
    
        document.addEventListener("backbutton", onBackKeyDown, false);
    }
    
    function success(phonenumber) {
        console.log("My number is " + phonenumber);
    }
    
    function failed(phonenumber) {
        console.log("Error " + phonenumber);
    }
    

    If your phone do not allow to show phonenumber then it will go to failed block.

    But from That : Some vendors don't publish the phone number to the SIM card.

    You can check it in Settings-> About Phone-> Status-> SIM Status.

提交回复
热议问题