Data Synchronization
PUBLISHED
You can synchronize device data, such as contacts and calendar events, with the OMA DS server using the OMA [1] DS (Data Synchronization) 1.2 protocol.
This feature is supported in mobile applications only.
The main features of the Data Synchronization API include:
- Creating a sync profile
You can create a profile, define the profile name, and provide other profile and operation information using the applicable interfaces.
Tizen sets a limitation on the number of supported OMA DS profiles on the device. Before creating a new profile, you must check whether sync profile slots are available.
- Retrieving synchronization process information
After starting the synchronization process, you can monitor the progress of the operation.
Prerequisites
To use the Data Synchronization [2] API, the application has to request permission by adding the following privilege to the config.xml
file:
<tizen:privilege name="http://tizen.org/privilege/datasync"/>
Creating a Sync Profile
To create a sync profile:
-
Check whether there are available profile slots on the device using the
getProfilesNum()
andgetMaxProfilesNum()
methods of the DataSynchronizationManager [3] interface:var numMaxProfiles = tizen.datasync.getMaxProfilesNum(); var numProfiles = tizen.datasync.getProfilesNum();
-
Create a sync profile. Use the SyncInfo [4], SyncServiceInfo [5], and SyncProfileInfo [6] interfaces to provide sync profile and operation information:
if ((numMaxProfiles <= 0) || (numProfiles < numMaxProfiles)) { var syncInfo = new tizen.SyncInfo('http://example.com/sync', 'myId', 'myPassword', 'MANUAL', 'TWO_WAY'); var contactInfo = new tizen.SyncServiceInfo(true, 'CONTACT', 'serverContact'); var eventInfo = new tizen.SyncServiceInfo(true, 'EVENT', 'serverEvent'); var serviceInfo = [contactInfo, eventInfo]; var profile = new tizen.SyncProfileInfo('MyProfile', syncInfo, serviceInfo);
-
To be able to use the created profile, add it to your device using the
add()
method of the DataSynchronizationManager [3] interface:tizen.datasync.add(profile); var profileId = profile.profileId; }
Starting and Monitoring Data Synchronization
After starting the synchronization process using the startSync()
method of the DataSynchronizationManager
interface, you can monitor the progress of the operation. Use the SyncProgressCallback [7] interface to define listeners for receiving notifications. After the synchronization is completed, you can retrieve statistics using the getLastSyncStatistics()
method.
To start and monitor the data synchronization process:
-
Define the event handlers for the notifications using the
SyncProgressCallback
listener interface:var syncCallback = { onprogress: function(profileId, serviceType, isFromServer, totalPerType, syncedPerType) { console.log('Total: ' + totalPerType + ', synced: ' + syncedPerType + ' for the sync type: ' + serviceType); }, onfailed: function(profileId, error) { console.log('Failed with id: ' + profileId + ', error name: ' + error.name); } };
-
Start the sync operation using the
startSync()
method, with the corresponding listener as a parameter:tizen.datasync.startSync(profileId, syncCallback);