Cordova Retrieve Phone Number and IMEI Android and iOS

0

I need to retrieve the phone number and imei with the cord, I tested some plugins but on my device I'm testing it did not work at all

My device is dual sim and with android 7.1

Is there any way to recover the phone number and imei in both cases?

    
asked by anonymous 16.03.2017 / 20:54

1 answer

0

As requested, the phone number could not recover because sometimes it returns null, but imei's is there:

plugin: link

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);
    })
  }
    
23.11.2017 / 11:10