Is there any way to get the unique device id from android

This question already has an answer here:

  • Is there a unique Android device ID? 40 answers

  • yes you can get android device mac id which is known as unique identifier assigned to network interfaces for communications on the physical network segment this is a unique id for each device which cannot be changed however.

    you can get it by WIFImanager in android

    WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = manager.getConnectionInfo();
    String MACAddress = wifiInfo.getMacAddress(); 
    

    dont forget to add permission to your manifest file

    <uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission>
    

    I don't think there's any (perfect) way to do this. See link. If you just want to identify the user, you can generate one UUID and store it in your application's storage.


    have created once class and use this in my app see pastie

    its create unique ID and generate MD5 message as string of unique device ID

    public String getUDID(Context c) {
    
        // Get some of the hardware information
        String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI
                + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST
                + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT
                + Build.TAGS + Build.TYPE + Build.USER;
    
        // Requires READ_PHONE_STATE
        TelephonyManager tm = (TelephonyManager) c
                .getSystemService(Context.TELEPHONY_SERVICE);
    
        // gets the imei (GSM) or MEID/ESN (CDMA)
           String imei = tm.getDeviceId();
    
          //gets the android-assigned id you can omit this because 
          //It's known to be null sometimes, it's documented as "can change upon factory reset". 
          //Use at your own risk, and it can be easily changed on a rooted phone.
        String androidId = Secure.getString(c.getContentResolver(),
                Secure.ANDROID_ID);
    
        // requires ACCESS_WIFI_STATE
        WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    
        // gets the MAC address
        String mac = wm.getConnectionInfo().getMacAddress();
    
        // concatenate the string
        String fullHash = buildParams + imei + androidId + mac;
    
        return md5(fullHash);
    
    }
    

    md5(String fullHash) Function

    public String md5(String toConvert) {
    
        String retVal = "";
    
        MessageDigest algorithm;
        try {
            algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(toConvert.getBytes());
            byte messageDigest[] = algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            retVal = hexString + "";
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return retVal;
    }
    
    链接地址: http://www.djcxy.com/p/24654.html

    上一篇: Android:在App更新中更改Android ID。 一些独特的东西呢?

    下一篇: 有没有什么办法从android获取唯一的设备ID