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
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<p_md5Data.length;i++) {
int b = (0xFF & p_md5Data[i]);
// if it is a single digit, make sure it have 0 in front (proper padding)
if (b <= 0xF) m_szUniqueID+="0";
// add number to string
m_szUniqueID+=Integer.toHexString(b);
}
// hex string to uppercase
m_szUniqueID = m_szUniqueID.toUpperCase();
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:
You are on right track for Sync process.
Device UDID (for iPhone) and Android_ID (for Android) is used for Push Notification only.
You can achieve Sync process without this.
For that, you need to follow below steps:
1) When app opens first time in device (iPhone/Android) then pass blank ("") date on server. So it will give you all data.
2) Store all data in local database for offline use. And also store server date locally.
3) Now, when user will open app next time, then pass previously stored data on server and it will give only latest added/updated data.
4) Make necessary changes add/edit in local database.
5) This way, you will have same data in web and both apps (iPhone & Android).
6) When user make changes in local data then set it's bit as "TRUE" in local database. So then when next sync perform, then check the SET bit and upload all data to server.
7) So, all data will be up-to-date at all web, iphone and android.
Hope you got an idea.
Happy Coding.
Cheers!