我已经花了几个小时尝试创建一个同步适配器。
同步设置总是处于未激活状态。为什么呢?
AndroidManifest
<provider
android:name="com.example.authenticating.DataProvider"
android:authorities="@string/content_authority"
android:exported="false"
android:multiprocess="true"
android:syncable="true" />
<service
android:name="com.example.authenticating.AuthenticatationService"
android:exported="true"
android:process=":auth">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
syncadapter.xml
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="@string/content_authority"
android:accountType="@string/sync_account_type"
android:userVisible="false"
android:supportsUploading="false"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="true" />
添加适配器
Account account = new Account(getString(R.string.sync_account_name), getString(R.string.sync_sync_account_type_name));
ContentResolver.setIsSyncable(account, getString(R.string.content_authority), 1);
accountManager.addAccountExplicitly(account, "", null);