Cordova Recover Phone Number and IMEI Android and iOS

Asked

Viewed 543 times

-1

I need to get my phone number back and I got it with Cordova, I tried some plugins but on my device that I am testing did not work any

my device is dual yes and android 7.1

there is some way to recover the phone number and Imei in both cases ?

  • Didn’t work, what? Are you trying to say that there was an exception or something else? Which plugins tried?

  • Undefined returns, I am currently tetando with this Cordova-plugin-yes

  • How is your code that returns this error?

  • window.plugins.sim.getSimInfo(successCallback, errorCallback);

  • tried this too and always caia error https://github.com/vliesaputra/DeviceInformationPlugin var deviceInfo = Cordova.require("Cordova/plugin/Deviceinformation"); deviceInfo.get(Function(result) { console.log("result = " + result); }, Function() { console.log("error"); });

  • and this https://github.com/aquto/cordova-plugin-imei ?

  • this one still won’t take a look, thanks for while

  • So I asked myself about that just now, I added here but not wanting to compile

  • error in xml config, I think I added the permission wrong... can tell me how to add correctly, according to Plugi the permission is READ_PHONE_STATE

  • can friend, <Feature name="Networkstatus"> <param name="android-package" value="Cdvconnection" /> </Feature>

  • Opa, posted as response, will help a lot of people, and post an example of how to install the plugin too ;)

  • I will do this, but first I want to see fully functional, the plugin returned several information except phone number, I’m seeing if you have any specific method but it seems that not

  • If possible, please post the answer to how you did

Show 8 more comments

1 answer

0

As requested, the phone number could not recover because sometimes returns null, but the of Imei is there:

plugin: https://github.com/pbakondy/cordova-plugin-sim

function errorCallback(error)
{
  console.log(error);
}

// Android only: check permission
function hasReadPermission()
{
  window.plugins.sim.hasReadPermission(successCallback, errorCallback);
}

// Android only: request permission
function requestReadPermission()
{
  window.plugins.sim.requestReadPermission(successCallback, errorCallback);
}

function retImei(callback){
  window.plugins.sim.hasReadPermission(
    function isAlowed(alowed){
      if (alowed != true) {
        window.plugins.sim.requestReadPermission(
          function returnedAlowed(returned){
            if (returned === 'OK'){
              window.plugins.sim.getSimInfo(
                function getResponse(response){
                  callback(response.deviceId);
                },
                errorCallback
              );
            } else {
              throwError('É necessário permitir acesso ao telefone');
            }
          },
          errorCallback
        );
      } else {
        window.plugins.sim.getSimInfo(
          function getResponse(response){
            callback(response.deviceId);
          },
          errorCallback
        );
      }
    }, errorCallback);
  }

  function getImei(){
    retImei(function returnImei(returned){
      myApp.alert(returned);
    })
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.