1

I need to get the IMEI number, Mobile number, SIM number in a Phonegap build HTML mobile web application for android

Ram Babu
  • 2,692
  • 3
  • 23
  • 28

3 Answers3

6

You cannot get them directly.

Option 1) look for some plugin I'm not sure if they exist or not.

Option 2) Write your own small script which returns what is needed.

For example I use this javascript code to get the IMEI in one of my app's:

$imei=window.YourActivityName.get_imei();

For this to work you need to enable javascript in your app and define function get_imei() in Java.

Your Java should look something like:

public class YourActivityName extends CordovaActivity 
{
.........
public void onCreate(Bundle savedInstanceState)
{
 .......
 appView.addJavascriptInterface(this, "YourActivityName");
 super.loadUrl(Config.getStartUrl(), 10000);
 .......
}

//Define function to return imei in Java:
@JavascriptInterface
public String get_imei() {
     TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();
    return imei;    
}
}
Emil Borconi
  • 3,326
  • 2
  • 24
  • 40
  • So I now can use the IMEI number. Thank you. But how can I get the sim card number and the mobile number? Help me please .. – Ram Babu Mar 30 '14 at 14:55
  • 2
    That was to get you on the track, it's not a complete solution, you can do similar approach for getting the desired values, but those are not that straight forward. It's nicely discussed over here: http://stackoverflow.com/questions/2480288/how-can-i-programmatically-obtain-the-number-of-the-android-phone-with-the-api – Emil Borconi Mar 30 '14 at 16:28
  • Dont forget to add in your AndroidManifest: – Chris Sim Jun 17 '14 at 08:10
1

You can get IMEI number using cordova plugin or java. But you can get device details instead IMEI number using device cordova plugin.

https://github.com/apache/cordova-plugin-device

Then use this script to get your device details in your javascript.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    console.log(device.cordova);
    console.log(device.model);
    console.log(device.name);
    console.log(device.platform);
    console.log(device.uuid);
    console.log(device.version);
    console.log(device.manufacturer);
    console.log(device.serial);
}

You can read more details about this plugin here.

https://github.com/apache/cordova-plugin-device/blob/master/doc/index.md

Rohit Suthar
  • 3,528
  • 1
  • 42
  • 48
Nurdin
  • 23,382
  • 43
  • 130
  • 308
  • So instead of IMEI number, I can use the UUID number. Thank you. But how can I get the sim card number and the mobile number? Help me please .. – Ram Babu Mar 30 '14 at 14:53
  • Can't because UUID number you can get only from itune. – Nurdin Mar 30 '14 at 17:30
1

There is one plugin which gives sim card details I tried it it gives phoneNumber for some operators like Telenor, Bsnl but I could not get phone number of Jio and Idea. First install plugin given in the link. as

cordova plugin add cordova-plugin-sim

Plugin link

I have sample code :

function get_number2(){
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
        if(window.plugins && window.plugins.sim){
            alert("plugin loaded");
            window.plugins.sim.getSimInfo(successCallback, errorCallback);

        }else{
            alert("plugin not loaded ");
        }

    }

    function successCallback(result) {
        alert("success");
        console.log(result);
        alert(result.carrierName);
        alert(result.countryCode);
        alert(result.mcc);
        alert(result.mnc);
        alert(result.phoneNumber);
        alert(result.cards[0].phoneNumber);
        alert(result.cards[1].phoneNumber);
    }

    function errorCallback(error) {
        alert("error");
        console.log(error);
        alert(error);
    }
 }
Thush-Fdo
  • 506
  • 1
  • 9
  • 28