0

Can anyone explain to me how to get the device's IMEI number from Phonegap? I am using the IMEI plugin in my app it is not showing anything.

To install, I have tried both:

phonegap plugin add https://github.com/zho/phonegap-imeiplugin.git

-- OR --

cordova plugin add imeiplugin

Example Usage:

window.plugins.imeiplugin.getImei(callback);

function callback(imei) {
    console.log("My Android IMEI :" + imei);

I want the output to be displayed when user opens the app, but it is not showing.

nycynik
  • 7,371
  • 8
  • 62
  • 87
abhi
  • 19
  • 1
  • 6

2 Answers2

1

here is the solution that how can you use imeiplugin Index.html

<!DOCTYPE html>
 <html>
   <body>
     <h1 id="demo"></h1>
    <script type="text/javascript" src="cordova.js"></script>
    <script src="js/index.js"></script>
    <script> app.initialize(); </script>
   </body>
 </html>

Index.js

var app = {
        // Application Constructor
        initialize: function () {
            app.bindEvents();
        },
        bindEvents: function () {
            document.addEventListener('deviceready', app.onDeviceReady, false);
        },
        onDeviceReady: function () {
            window.plugins.imeiplugin.getImei(callback);    
        }
    };
    function callback(imei) {
        var element=document.getElementById("demo");
        element.value=imei;

    }
Hassan ALi
  • 1,313
  • 1
  • 23
  • 51
0

There is something wrong with the plugin you provided it showing an error like imeiplugin is unefined at window.plugins.imeiplugin.getImei(callback);

so i tried with the below and its worked for me

cordova plugin add org.hygieiasoft.cordova.uid

and call the finction on device ready

 document.addEventListener('deviceready', onDeviceReady, false);
    function onDeviceReady() {
        console.log(cordova.plugins.uid.IMEI);
    }

check this for more info

Sa E Chowdary
  • 2,075
  • 15
  • 31