Android/Iphone device data distinction in web-application?

前端 未结 2 1115
无人及你
无人及你 2021-02-11 07:14

So, I am working on the database architecture of a web application which would have its android and iphone apps developed also.

And for that I want to create a column n

2条回答
  •  我寻月下人不归
    2021-02-11 08:09

    Guessing you are done with sync process(@Nishant B's post), now for Unique ID here is the code snippet which works almost for all Android devices (Tab + Mobile).

    Now as you know, there is no guarantee of any Unique ID in Android so its better to create a key which will generate as a combination of multiple key and Unique on every time we generate...

    TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
    String szImei = TelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE
    
    String m_szDevIDShort = "35" + //we make this look like a valid IMEI
    Build.BOARD.length()%10+ Build.BRAND.length()%10 +
    Build.CPU_ABI.length()%10 + Build.DEVICE.length()%10 +
    Build.DISPLAY.length()%10 + Build.HOST.length()%10 +
    Build.ID.length()%10 + Build.MANUFACTURER.length()%10 +
    Build.MODEL.length()%10 + Build.PRODUCT.length()%10 +
    Build.TAGS.length()%10 + Build.TYPE.length()%10 +
    Build.USER.length()%10 ; //13 digits
    
    
    WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
    
    BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter
    m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    String m_szBTMAC = m_BluetoothAdapter.getAddress();
    String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
    
    
    String m_szLongID = m_szImei + m_szDevIDShort + m_szWLANMAC + m_szBTMAC;
    // compute md5
    MessageDigest m = null;
    try {
         m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    }
    
    m.update(m_szLongID.getBytes(),0,m_szLongID.length());
    // get md5 bytes
    byte p_md5Data[] = m.digest();
    // create a hex string
    String m_szUniqueID = new String();
    
    for (int i=0;i

    here we had taken IMEI, Manufacturer Board detail, Wifi address and Bluetooth address (not taking ANDROID_ID as its change when factory reset). with combinition of these key one can generate a Unique key(m_szUniqueID) with the help of MD5.

    I'm sure with the help of this above you can generate a unique key everytime.

    Good points:

    • Its not vary on consecutive generation on same device which mean one device will have only one ID and i.e. Unique.
    • Even work with non registered device i.e. device without IMEI numbers.
    • works with Tablet too.

提交回复
热议问题