I'm developing a PhoneGap Android mobile application using jQuery, JavaScript and HTML. I want to get the mobile IMEI. I have tried this code from this Tutorial.
I am getting the number like this: 97734a345d234d.
I have checked my device to get IMEI number using *#06#
.
I don't know whether it is correct or not.
You could write a phonegap plugin to return you the IMEI number. As the phonegap doesnt return imei for Android devices, it returns an random 64-bit number.
Here is a complete plugin to get the real IMEI number in a phonegap application (please note that this plugin is not "plugmanable" but if follow the instructions it will work. I have tested on phonegap 2.9. I am planning on writing a real "plugmanable" plugin with a few device information for phonegap 3.0).
Here is the java class for that extends from CordovaPlugin (DeviceInfo.java):
And then you need a js object so you can access your plugin on the other side (deviceinfo.js):
Add your plugin on res/xml/config.xml file inside your project like this:
And add the READ_PHONE_STATE permission inside your AndroidManifest.xml:
After this you need to add you deviceinfo.js file into your page, and after the deviceready you can use your plugin like this:
You're pointing to PhoneGap Tutorial version 1.0.0. It is very old and it lacs a lot of information. If you, for example, read the very same page for version 2.1.0 of PhoneGap you'll notice a comment made for device.uuid Quick Example, where it is said, that
device.uuid
returns IMEI number only in case of Tizen platform. All other platforms, including Android, you mentioned, does return something else.You can't get device's IMEI in pure HTML / Javascript (application compiled through PhoneGap Build). To read it, you have to build locally, for Android platform only and include some native plugin that will do the job for you -- for example something like this one.
You cannot access the IMEI via html or JavaScript. But you can write an app which reads the IMEI for you.
Just call getDeviceId(). Don't forget that you need the READ_PHONE_STATE permission in your manifest.
Fetch the IMEI number in the class which extends DroidGap class and save the value of imei number in static member and then access this static field from where ever you want... example code is here
You can use the "Device" object from Phonegap. Since "device" is assigned to the window object, it is implicitly in the global scope so you can easily call it in your onDeviceReady function eg:
Please note that on Android it returns a random 64-bit integer as a string. The integer is generated on the device's first boot. On BlackBerry it returns the PIN number of the device. This is a nine-digit unique integer as a string and on iPhone it returns a string of hash values created from multiple hardware identifies.It is guaranteed to be unique for every device and cannot be tied to the user account.
See the full example here
I have created a plugin called
cordova-plugin-imeigetter
for cordova (only for Android devices) that does what you want. I hope it helps you.Installation:
Usage:
This plugin exports an object with one method called
get
:GitHub: https://github.com/tomloprod/cordova-plugin-imeigetter