How do I use the Android SyncAdapter?

后端 未结 3 385
既然无缘
既然无缘 2020-12-12 11:12

I try to understand the Android synchronization logic. What I don\'t understand is the file syncadapter.xml contained in the Android SDK sample project Sa

3条回答
  •  轮回少年
    2020-12-12 11:44

    It is a way to create relation between an Account-type,Sync Adapter and a Content Authority

    Looking back again at AndroidManifest, that strange meta-data tag in Sync service is the key piece that establishes the binding between a ContentAuthority and an account. It externally references another xml file (call it whatever you like, something relevant to your app.)

    Let's look at sync_myapp.xml:

        
    

    It tells Android that the sync adapter we've defined (the class that was called out in the name element of the tag that includes the tag that includes this file, will sync contacts using a com.example.android.samplesync style account. Account type and Authority is unique for your application.

    All your contentAuthority strings have to all match, and match with what you're syncing -- This should be a string you define, if you're creating your own database, or you should use some existing device strings if you're syncing known data types (like contacts or calendar events or what have you.) The above ("com.android.contacts") happens to be the ContentAuthority string for contacts type data (surprise, surprise.)

    accountType also has to match one of those known account types that are already entered, or it has to match one you're creating.

    Last userVisible true means shown to user.

提交回复
热议问题