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

这个问题在这里已经有了答案:

  • 是否有唯一的Android设备ID? 40个答案

  • 是的,你可以得到android设备MAC ID,这被称为唯一标识符分配给物理网段上的通信的网络接口,这是每个设备的唯一ID,但无法更改。

    你可以通过Android中的WIFImanager获取它

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

    不要忘记为清单文件添加权限

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

    我不认为有任何(完美)的方式来做到这一点。 请参阅链接。 如果您只想识别用户,您可以生成一个UUID并将其存储在应用程序的存储中。


    创建了一次课程,并在我的应用程序中使用它可以看到pastie

    它创建唯一的ID并生成MD5消息作为唯一设备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)函数

    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/24653.html

    上一篇: Is there any way to get the unique device id from android

    下一篇: how to get an android device ID