<body onload="prettyPrint()" style="overflow: auto;">
<div id="toc-navigation">
- <div id="profile">
- <p><img alt="Mobile C#" src="../images/mobile_s_cs.png"/></p>
- </div>
+
<div id="toc_border"><div id="toc">
<p class="toc-title">Dependencies</p>
<ul class="toc">
- <li>Tizen 4.0 and Higher for Mobile</li>
+ <li>Tizen 4.0 and Higher</li>
</ul>
<p class="toc-title">Content</p>
<ul class="toc">
<h2 id="set_callback">Setting Sync Adapter Callbacks</h2>
<p>To set callbacks in your Sync Adapter service application that your UI application can call to request sync operations:</p>
<ol>
- <li>Set up event handlers for starting and stopping data synchronization. When the <code>startCb</code> callback is invoked, the predefined data sync process is performed inside the callback method. The <code>cancelCb</code> callback works in a similar way and cancels the data sync process.
+ <li>Set up event handlers for starting and stopping data synchronization. When the <code>StartSyncCallback</code> callback is invoked, the predefined data sync process is performed inside the callback method. The <code>CancelSyncCallback</code> callback works in a similar way and cancels the data sync process.
<pre class="prettyprint">
-SyncAdapter.StartSyncCallback startCb = (SyncJobData data) =>
+static bool StartSyncCallback(SyncJobData data)
{
/// Code for starting data synchronization
+
return true;
-};
+}
-SyncAdapter.CancelSyncCallback cancelCb = (SyncJobData data) =>
+static void CancelSyncCallback(SyncJobData data)
{
/// Code for cancelling data synchronization
-};
+}
</pre>
</li>
<p>When a specific event is detected or a sync job is requested, the <code>StartSyncCallback</code> or <code>CancelSyncCallback</code> events of the <code>Tizen.Account.SyncManager.SyncAdapter</code> class are invoked.</p>
<pre class="prettyprint">
SyncAdapter obj = new SyncAdapter();
-obj.SetSyncEventCallbacks(startCb, cancelCb);
+obj.SetSyncEventCallbacks(StartSyncCallback, CancelSyncCallback);
</pre>
</li>
<li>When the sync operations are no longer needed, unset the callbacks to free the <code>Tizen.Account.SyncManager.SyncAdapter</code> instance:
<pre class="prettyprint">
-SyncAdapter obj = new SyncAdapter();
obj.UnsetSyncEventCallbacks();
</pre>
</li>
<h2 id="set_parameters">Defining a Sync Job</h2>
<p>To define a sync job, create a new <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance:</p>
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = "PeriodicSyncJob";
+SyncJobData request = new SyncJobData();
+request.SyncJobName = "PeriodicSyncJob";
</pre>
<p>You can add user data to a sync job as an account information instance or as a data bundle:</p>
AccountManager.Account account = AccountManager.Account.CreateAccount();
account.UserName = "Kim";
+AccountService.AddAccount(account);
-SyncData.Account = account;
+SyncJobData request = new SyncJobData();
+request.Account = account;
</pre>
</li>
Applications.Bundle bundle = new Applications.Bundle();
bundle.AddItem("key", "value");
-SyncData.UserData = bundle;
+SyncJobData request = new SyncJobData();
+request.UserData = bundle;
</pre>
</li>
</ul>
<ul>
<li>To set up a periodic sync job with a regular sync interval, use the <code>AddPeriodicSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class, and give the sync interval as a value of the <code>Tizen.Account.SyncManager.SyncPeriod</code> enumeration. In the following example, the sync interval is set to 30 minutes:
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = "PeriodicSyncJob";
-int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.ThirtyMin, SyncOption.None);
+SyncJobData request = new SyncJobData();
+request.SyncJobName = "PeriodicSyncJob";
+int id = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.ThirtyMin, SyncOption.None);
</pre>
<p>You can also add additional parameters to the sync job using values of the <code>Tizen.Account.SyncManager.SyncOption</code> enumeration. The value <code>NoRetry</code> means that the application does not retry the sync job if it fails, and <code>Expedited</code> means that the sync job is handled as soon as possible.</p>
<pre class="prettyprint">
-int id2 = SyncClient.AddPeriodicSyncJob(SyncData2, SyncPeriod.OneHour, SyncOption.NoRetry);
-int id3 = SyncClient.AddPeriodicSyncJob(SyncData3, SyncPeriod.OneDay, SyncOption.Expedited);
+id = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.OneHour, SyncOption.NoRetry);
+id = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.OneDay, SyncOption.Expedited);
</pre>
</li>
<li>You can renew a previously registered periodic sync job with the <code>AddPeriodicSyncJob()</code> method by using the same <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance with new parameters:
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = "PeriodicSyncJob";
-int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.ThirtyMin, SyncOption.None);
-id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.TwoHours, SyncOption.Expedited);
+SyncJobData request = new SyncJobData();
+request.SyncJobName = "PeriodicSyncJob";
+int id = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.ThirtyMin, SyncOption.None);
+id = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.TwoHours, SyncOption.Expedited);
</pre>
</li>
</ul>
<ul>
<li>Add a data change sync job with the <code>AddDataChangeSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class. This method adds the sync job only for the capability given as the value of the <code>SyncJobName</code> property of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance. For example, to add a data change sync job for the calendar:
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = SyncJobData.CalendarCapability;
-int id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.None);
+SyncJobData request = new SyncJobData();
+request.SyncJobName = SyncJobData.CalendarCapability;
+int id = SyncClient.AddDataChangeSyncJob(request, SyncOption.None);
</pre>
<p>You can also add additional parameters to the sync job using values of the <code>Tizen.Account.SyncManager.SyncOption</code> enumeration. The value <code>NoRetry</code> means that the application does not retry the sync job if it fails, and <code>Expedited</code> means that another sync job is handled as soon as possible.</p>
<pre class="prettyprint">
-int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.NoRetry);
-int id3 = SyncClient.AddDataChangeSyncJob(SyncData3, SyncOption.Expedited);
+SyncJobData request2 = new SyncJobData();
+request2.SyncJobName = SyncJobData.ContactCapability;
+SyncJobData request3 = new SyncJobData();
+request3.SyncJobName = SyncJobData.ImageCapability;
+int id2 = SyncClient.AddDataChangeSyncJob(request2, SyncOption.NoRetry);
+int id3 = SyncClient.AddDataChangeSyncJob(request3, SyncOption.Expedited);
</pre>
</li>
<li>You can renew a previously registered data change sync job with the <code>AddDataChangeSyncJob()</code> method by using the same <code>Tizen.Account.SyncManager.SyncJobData</code> instance with new parameters:
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = SyncJobData.ContactCapability;
-int id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.Expedited);
-id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.None);
+SyncJobData request = new SyncJobData();
+request.SyncJobName = SyncJobData.ContactCapability;
+int id = SyncClient.AddDataChangeSyncJob(request, SyncOption.Expedited);
+id = SyncClient.AddDataChangeSyncJob(request, SyncOption.None);
</pre>
</li>
</ul>
<h2 id="foreach_sync">Retrieving All Registered Sync Jobs</h2>
<p>To retrieve a list of all registered sync jobs, use the <code>GetAllSyncJobs()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class:</p>
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = "PeriodicSyncJob";
-
-SyncJobData SyncData2 = new SyncJobData();
-SyncData2.SyncJobName = SyncJobData.ImageCapability;
+SyncJobData request = new SyncJobData()
+{
+ SyncJobName = "PeriodicSyncJob"
+};
+int periodicId = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.ThreeHours, SyncOption.None);
-int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.OneHour, SyncOption.Expedited);
-int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.None);
+SyncJobData request2 = new SyncJobData()
+{
+ SyncJobName = SyncJobData.MusicCapability
+};
+int dataChangeId = SyncClient.AddDataChangeSyncJob(request2, SyncOption.None);
-foreach (var pair in <span class="highlight">SyncClient.GetAllSyncJobs()</span>)
+IEnumerable<KeyValuePair<int, SyncJobData>> syncJobs = <span class="highlight">SyncClient.GetAllSyncJobs();</span>
+foreach (KeyValuePair<int, SyncJobData> item in syncJobs)
{
- Console.Write(pair.Key + ": ");
- Console.WriteLine(pair.Value);
+ if (item.Key == periodicId)
+ {
+ Console.WriteLine(item.Value.SyncJobName.ToString());
+ }
+ if (item.Key == datachangeId)
+ {
+ Console.WriteLine(item.Value.SyncJobName.ToString());
+ }
}
</pre>
<h2 id="remove_sync">Removing Sync Jobs</h2>
<p>To remove registered sync jobs, use the <code>RemoveSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class, using the <code>id</code> property of the job to be removed:</p>
<pre class="prettyprint">
-SyncJobData SyncData = new SyncJobData();
-SyncData.SyncJobName = "PeriodicSyncJob";
+SyncJobData request = new SyncJobData();
+request.SyncJobName = "PeriodicSyncJob";
-SyncJobData SyncData2 = new SyncJobData();
-SyncData2.SyncJobName = SyncJobData.ImageCapability;
+SyncJobData request2 = new SyncJobData();
+request2.SyncJobName = SyncJobData.ImageCapability;
-int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.OneHour, SyncOption.Expedited);
-int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.None);
+int id = SyncClient.AddPeriodicSyncJob(request, SyncPeriod.OneHour, SyncOption.Expedited);
+int id2 = SyncClient.AddDataChangeSyncJob(request2, SyncOption.None);
<span class="highlight">SyncClient.RemoveSyncJob(id);</span>
<span class="highlight">SyncClient.RemoveSyncJob(id2);</span>