I am writing an application that uses a synchronization adapter to synchronize data.
I read the documentation and I'm sure I understand how it all works. I have most of my sync adapter working, following this excellent tutorial written by Udi Cohen.
However, I have one problem that I cannot solve, and this allows me to automatically synchronize when my application is installed.
When my application starts, it creates a sync adapter and an account, does all the work that you expect from it, and that's great. However, if I go to Settings> Accounts> My Application, sync is disabled. Anyway, can I get this to automatically activate?
Account Screenshot> My Application
When setting up the sync adapter, my code is as follows:
if(accountManager.addAccountExplicitly(account,null,null))
{
ContentResolver.setIsSyncable(account, CONTENT_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, CONTENT_AUTHORITY, true);
ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY, new Bundle(), SYNC_FREQUENCY);
newAccount = true;
}
From reading synchronization adapters, I thought I ContentResolver.setSyncAutomatically()was the right method for automatic synchronization.
I also tried to install ContentResolver.setMasterSyncAutomatically(true);, but this has no effect.
android.permission.WRITE_SYNC_SETTINGS, AndroidManifest, . xml . .
- ? ?
- , . .
AndroidManifest.xml
<service
android:name=".syncadapter.CalendarSyncService"
android:exported="true"
android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/calendar_syncadapter"/>
</service>
syncadapter.xml
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.companyname.rostering"
android:allowParallelSyncs="true"
android:contentAuthority="com.android.calendar"
android:isAlwaysSyncable="true"
android:supportsUploading="true"
android:userVisible="true"/>