2010-07-13 65 views
5

我正在爲android設備編寫我自己的SyncAdapter,它應該將TV廣播信息同步到設備,但遇到了無法獲得同步「mydata」複選框在Data &同步部分帳戶首選項下可見的問題。如何在Android中啓用自定義帳戶的同步?

我已經實現了我自己的SyncAdapter並在XML正確定義它:

這裏是我的sync.xml:

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" 
    android:contentAuthority="com.example.tv.programs" 
    android:accountType="com.example.tv.sync" 
    android:supportsUploading="false" 
    android:userVisible="true" 
/> 

相應的Android清單的一部分,在這裏我定義我的同步服務和提供商:

<service android:name=".sync.ProgramSynchronizationService" android:exported="true" android:process=":programs"> 
    <intent-filter> 
     <action android:name="android.content.SyncAdapter" /> 
    </intent-filter> 
    <meta-data 
     android:name="android.content.SyncAdapter" 
     android:resource="@xml/sync" /> 
</service> 

<provider android:name="com.example.tv.providers.ProgramContentProvider" 
    android:authorities="com.example.tv.programs" /> 

上午我做錯了什麼,因爲我沒有得到任何數據&同步一部分下可見?

回答

10

除了您的同步適配器設置,您還需要調用(比如在程序啓動):

ContentResolver.setIsSyncable(account, "com.example.tv.programs", 1) 
3

要添加到這一點,如果你想啓用同步自動,你可以做

ContentResolver.setSyncAutomatically(account, "com.example.tv.programs",true); 
+0

Android文檔建議,這樣做會導致每幾秒鐘同步一次。請你能回答我的問題:http://stackoverflow.com/questions/22206596/how-to-enable-sync-without-syncing-every-few-seconds? – cja 2014-03-05 19:10:46