How to get IMEI number in PhoneGap?

前端 未结 8 506
北海茫月
北海茫月 2020-12-03 11:30

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

相关标签:
8条回答
  • 2020-12-03 11:40

    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:

    cordova plugin add https://github.com/tomloprod/cordova-plugin-imeigetter.git
    

    Usage:

    This plugin exports an object with one method called get:

    window.plugins.imeiGetter.get(function(imei){
       console.log(imei);
    });
    

    GitHub: https://github.com/tomloprod/cordova-plugin-imeigetter

    0 讨论(0)
  • 2020-12-03 11:44

    I believe this would only be possible if you exploit some other apps logging of the IMEI and I'm not sure if any do.

    Assuming some do, ideally a system app, you can read the logs and parse them for that information.

    Good luck, post back with successes/failures

    0 讨论(0)
  • 2020-12-03 11:49

    You may change getUuid function defined in platforms/android/src/org/apache/cordova/device/Device.java in this way

    public String getUuid() {
        //String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
        TelephonyManager tManager = (TelephonyManager)this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String uuid = tManager.getDeviceId();
        return uuid;
    }
    

    just comment the first line and add the two new ones.

    You also have to add

    import android.content.Context;
    import android.telephony.TelephonyManager;
    
    0 讨论(0)
  • 2020-12-03 11:53

    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:

    var deviceID = device.uuid
    

    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

    0 讨论(0)
  • 2020-12-03 11:54

    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.

    0 讨论(0)
  • 2020-12-03 11:56

    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

    public class MyApp extends DroidGap
    {
        private static String imei; 
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            super.loadUrl("file:///android_asset/www/index.html");
            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            imei=tm.getDeviceId();
        }
        static public String getIMEI(){
            return imei;
        }
    }
    // where ever u need imei number use this code
    
    String imei=MyApp.getIMEI();
    
    0 讨论(0)
提交回复
热议问题