Sharing data across Android / Iphone devices in a web app?

So I am working on a web application database architecture that would also develop android and iphone apps.

And for that, I want to create a column name device_id

in mysql database

to keep track of whether the user is using the app via web app or android-app or iphone-app .

Below are a few functional points:

Create / Register

  • Can be done with web-app / android-app / iphone-app.

To come in

  • It doesn't matter where the custom creation was created, the User can log in from all sides based on a central database on the Internet (using the web login service).

Problem area

You don't have any facts, but some of my technicians reported that:

Iphone and Android that previously provided UDID and ANDROID_ID in the past will not do so in future releases.

Now

The mobile app works even without an internet connection and so I developed a sync tool for the same one that will sync data on the device with the website and on the device when a button is pressed.

In some cases, the same user may be used , who also uses the application from different devices and the Internet , so that the data is synchronized on the device and network.

Hence, what would be best for this, I could automatically generate some unique sequence and not rely on the device ID for the sync process.

--- Edit ---

In a factory reset and rooted device, make sure that the device will not return a unique ID, as well as various development firms working on customizing Android and therefore this is not a guarantee for a unique device ID. So how can I get the best solution? logic at the end and on the internet.

+1


source to share


2 answers


Guessing that you have finished the sync process (@Nishant B post), now for the unique ID, here's a piece of code that works for almost all Android devices (Tab + Mobile).

Now, as you know, in Android there is no guarantee for a unique identifier, so it is better to create a key that will be generated as a combination of several keys and unique ones on each creation ...

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 accepted IMEI, manufacturer details, Wifi address and Bluetooth address (not taking ANDROID_ID as changing it when factory reset). with a combination of this key, you can create a unique key ( m_szUniqueID

) using MD5.



I am sure that with this above, you can generate a unique key every time.

Good scores:

  • It does not change on successive generations on one device, which means that one device will only have one identifier and therefore unique.
  • Even working with an unregistered device, that is, a device without IMEI numbers.
  • also works with tablets.
+4


source


You are on the right track for the synchronization process.

Device UDID (for iPhone) and Android_ID (for Android) is only used for Push Notification.

You can complete the sync process without this.

To do this, you need to follow these steps:

1) When the application is opened for the first time on the device (iPhone / Android), a blank ("") date is sent to the server. Thus, it will provide you with all the data.

2) Store all data in a local database for offline use. And also store the server date locally.

3) Now when the user open the app next time, then transfer the previously saved data to the server and it will only provide the last added / updated data.



4) Make the necessary changes to the local database.

5) This way, you will have the same data on the Internet and in both applications (iPhone and Android).

6) When the user makes changes to local data, set the bit to "TRUE" in the local database. Then when the next sync is in progress, check the SET bit and upload all data to the server.

7) So, all data will be updated on all websites, iphone and Android.

Hope you have an idea.

Happy coding.

Hooray!

+2


source







All Articles