Home | History | Annotate | Download | only in providers
      1 page.title=Trnh cung cp Danh b
      2 @jd:body
      3 <div id="qv-wrapper">
      4 <div id="qv">
      5 <h2>Xem nhanh</h2>
      6 <ul>
      7     <li>Kho lu gi thng tin v con ngi ca Android.</li>
      8     <li>
      9         ng b vi web.
     10     </li>
     11     <li>
     12         Tch hp d liu theo lung x hi.
     13     </li>
     14 </ul>
     15 <h2>Trong ti liu ny</h2>
     16 <ol>
     17     <li>
     18         <a href="#InformationTypes">T chc Trnh cung cp Danh b</a>
     19     </li>
     20     <li>
     21         <a href="#RawContactBasics">Lin lc th</a>
     22     </li>
     23     <li>
     24         <a href="#DataBasics">D liu</a>
     25     </li>
     26     <li>
     27         <a href="#ContactBasics">Danh b</a>
     28     </li>
     29     <li>
     30         <a href="#Sources">D liu t Trnh iu hp ng b</a>
     31     </li>
     32     <li>
     33         <a href="#Permissions">Quyn c Yu cu</a>
     34     </li>
     35     <li>
     36         <a href="#UserProfile">H s Ngi dng</a>
     37     </li>
     38     <li>
     39         <a href="#ContactsProviderMetadata">Siu d liu Trnh cung cp Danh b</a>
     40     </li>
     41     <li>
     42         <a href="#Access">Truy cp Trnh cung cp Danh b</a>
     43     <li>
     44     </li>
     45     <li>
     46         <a href="#SyncAdapters">Trnh iu hp ng b Trnh cung cp Danh b</a>
     47     </li>
     48     <li>
     49         <a href="#SocialStream">D liu t Lung X hi</a>
     50     </li>
     51     <li>
     52         <a href="#AdditionalFeatures">Cc Tnh nng B sung ca Trnh cung cp Danh b</a>
     53     </li>
     54 </ol>
     55 <h2>Lp kha</h2>
     56 <ol>
     57     <li>{@link android.provider.ContactsContract.Contacts}</li>
     58     <li>{@link android.provider.ContactsContract.RawContacts}</li>
     59     <li>{@link android.provider.ContactsContract.Data}</li>
     60     <li>{@code android.provider.ContactsContract.StreamItems}</li>
     61 </ol>
     62 <h2>Cc Mu Lin quan</h2>
     63 <ol>
     64     <li>
     65         <a href="{@docRoot}resources/samples/ContactManager/index.html">
     66         Trnh qun l Danh b
     67         </a>
     68     </li>
     69     <li>
     70         <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">
     71         Trnh iu hp ng b Mu</a>
     72     </li>
     73 </ol>
     74 <h2>Xem thm</h2>
     75 <ol>
     76     <li>
     77         <a href="{@docRoot}guide/topics/providers/content-provider-basics.html">
     78         Ni dung C bn v Trnh cung cp Ni dung
     79         </a>
     80     </li>
     81 </ol>
     82 </div>
     83 </div>
     84 <p>
     85     Trnh cung cp Danh b l mt thnh phn Android mnh m v linh hot c chc nng qun l
     86     kho d liu trung tm v con ngi ca thit b. Trnh cung cp Danh b l ngun ca nhng d liu
     87     m bn thy trong ng dng danh b ca thit b, v bn cng c th truy cp d liu ca n trong
     88     ng dng ca chnh mnh v chuyn d liu gia thit b v cc dch v trc tuyn. Trnh cung cp cha
     89      loi ngun d liu v c gng qun l nhiu d liu nht c th cho mi ngi, kt qu
     90     l t chc ca n tr nn phc tp. V iu ny, API ca trnh cung cp bao gm mt
     91     tp m rng gm cc lp hp ng v giao din to iu kin cho vic truy xut v sa i
     92     d liu.
     93 </p>
     94 <p>
     95     Hng dn ny trnh by nhng ni dung sau:
     96 </p>
     97     <ul>
     98         <li>
     99             Cu trc c bn ca trnh cung cp.
    100         </li>
    101         <li>
    102             Cch truy xut d liu t trnh cung cp.
    103         </li>
    104         <li>
    105             Cch sa i d liu trong trnh cung cp.
    106         </li>
    107         <li>
    108             Cch ghi mt trnh iu hp ng b  ng b ha d liu t my ch ca bn vi
    109             Trnh cung cp Danh b.
    110         </li>
    111     </ul>
    112 <p>
    113     Hng dn ny gi s rng bn bit nhng ni dung c bn v trnh cung cp ni dung Android.  tm hiu thm
    114     v trnh cung cp ni dung Android, hy c hng dn
    115     <a href="{@docRoot}guide/topics/providers/content-provider-basics.html">
    116     Ni dung C bn v Trnh cung cp Ni dung</a>. ng dng mu
    117     <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">Trnh iu hp ng b Mu</a>
    118     l mt v d v cch s dng mt trnh iu hp ng b  chuyn d liu gia Trnh cung cp
    119     Danh b v ng dng mu c lu tr bi Dch v Web Google.
    120 </p>
    121 <h2 id="InformationTypes">T chc Trnh cung cp Danh b</h2>
    122 <p>
    123     Trnh cung cp Danh b l mt thnh phn ca trnh cung cp ni dung Android. N cha ba loi
    124     d liu v mt ngi, tng loi tng ng vi mt bng do trnh cung cp a ra, nh
    125     c minh ha trong hnh 1:
    126 </p>
    127 <img src="{@docRoot}images/providers/contacts_structure.png" alt="" height="364" id="figure1" />
    128 <p class="img-caption">
    129   <strong>Hnh 1.</strong> Cu trc bng ca Trnh cung cp Danh b.
    130 </p>
    131 <p>
    132     Ba bng ny thng c  cp theo tn cc lp hp ng ca chng. Cc lp ny
    133     s nh ngha cc hng s cho URI ni dung, tn ct v gi tr ct c s dng bi cc bng:
    134 </p>
    135 <dl>
    136     <dt>
    137         Bng {@link android.provider.ContactsContract.Contacts}
    138     </dt>
    139     <dd>
    140         Hng th hin nhng ngi khc nhau da trn tng hp ca cc hng lin lc th.
    141     </dd>
    142     <dt>
    143         Bng {@link android.provider.ContactsContract.RawContacts}
    144     </dt>
    145     <dd>
    146         Hng cha mt bn tng hp d liu v mt ngi, lin quan ti ti khon v loi ngi dng.
    147     </dd>
    148     <dt>
    149         Bng {@link android.provider.ContactsContract.Data}
    150     </dt>
    151     <dd>
    152         Hng cha cc thng tin chi tit v lin lc th, chng hn nh a ch e-mail hoc s in thoi.
    153     </dd>
    154 </dl>
    155 <p>
    156     Cc bng khc c i din bi cc lp hp ng trong {@link android.provider.ContactsContract}
    157     l bng ph m Trnh cung cp Danh b s dng  qun l thao tc ca n hoc h tr
    158     cc chc nng c th trong ng dng danh b hoc in thoi ca thit b.
    159 </p>
    160 <h2 id="RawContactBasics">Lin lc th</h2>
    161 <p>
    162     Mt lin lc th th hin d liu ca mt ngi xut pht t mt loi ti khon v tn ti khon
    163  ring. V Trnh cung cp Danh b cho php nhiu hn mt dch v trc tuyn lm ngun
    164  d liu cho mt ngi, Trnh cung cp Danh b cho php nhiu lin lc th cho cng mt ngi.
    165     Nhiu lin lc th cng cho php ngi dng kt hp d liu ca mt ngi t nhiu hn mt ti khon
    166  t cng loi ti khon.
    167 </p>
    168 <p>
    169     Hu ht d liu ca mt lin lc th khng c lu gi trong bng
    170     {@link android.provider.ContactsContract.RawContacts}. Thay vo , n c lu gi trong mt hoc nhiu
    171     hng trong bng {@link android.provider.ContactsContract.Data}. Mi hng d liu c mt ct
    172     {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID Data.RAW_CONTACT_ID} cha
    173     gi tr {@code android.provider.BaseColumns#_ID RawContacts._ID} ca
    174     hng {@link android.provider.ContactsContract.RawContacts} m ca n.
    175 </p>
    176 <h3 id="RawContactsColumns">Cc ct lin lc th quan trng</h3>
    177 <p>
    178     Cc ct quan trng trong bng {@link android.provider.ContactsContract.RawContacts} c
    179     lit k trong bng 1. Hy c cc lu  theo sau bng di y:
    180 </p>
    181 <p class="table-caption" id="table1">
    182     <strong>Bng 1.</strong> Cc ct lin lc th quan trng.
    183 </p>
    184 <table>
    185     <tr>
    186         <th scope="col">Tn ct</th>
    187         <th scope="col">S dng</th>
    188         <th scope="col">Lu </th>
    189     </tr>
    190     <tr>
    191         <td>
    192             {@link android.provider.ContactsContract.SyncColumns#ACCOUNT_NAME}
    193         </td>
    194         <td>
    195             Tn ti khon cho loi ti khon l ngun ca lin lc th ny.
    196             V d, tn ti khon ca mt ti khon Google l mt trong cc a ch Gmail
    197             ca ch s hu thit b. Xem mc nhp tip theo cho
    198             {@link android.provider.ContactsContract.SyncColumns#ACCOUNT_TYPE}  bit thm
    199             thng tin.
    200         </td>
    201         <td>
    202             nh dng ca tn ny p dng theo loi ti khon ca n.  khng nht thit
    203             l mt a ch e-mail.
    204         </td>
    205     </tr>
    206     <tr>
    207         <td>
    208             {@link android.provider.ContactsContract.SyncColumns#ACCOUNT_TYPE}
    209         </td>
    210         <td>
    211             Loi ti khon l ngun ca lin lc th ny. V d, loi ti khon
    212             ca mt ti khon Google l <code>com.google</code>. Lun xc nh loi ti khon ca bn
    213             bng mt m nh danh min cho mt min m bn s hu hoc kim sot. iu ny m bo rng loi ti khon
    214             ca bn l duy nht.
    215         </td>
    216         <td>
    217             Mt loi ti khon cung cp d liu danh b thng c mt trnh iu hp ng b lin kt 
    218             ng b ho vi Trnh iu hp ng b.
    219     </tr>
    220     <tr>
    221         <td>
    222             {@link android.provider.ContactsContract.RawContactsColumns#DELETED}
    223         </td>
    224         <td>
    225             C " xa" cho mt lin lc th.
    226         </td>
    227         <td>
    228             C ny cho php Trnh cung cp Danh b duy tr hng bn trong ti khi trnh iu hp ng b
    229             c th xa hng  khi my ch ca chng ri cui cng l xa hng
    230             khi kho lu gi.
    231         </td>
    232     </tr>
    233 </table>
    234 <h4>Lu </h4>
    235 <p>
    236     Sau y l cc ghi ch quan trng v bng
    237     {@link android.provider.ContactsContract.RawContacts}:
    238 </p>
    239 <ul>
    240     <li>
    241         Tn ca lin lc th khng c lu gi trong hng ca n trong
    242         {@link android.provider.ContactsContract.RawContacts}. Thay vo , n c lu gi trong
    243         bng {@link android.provider.ContactsContract.Data}, trong mt hng
    244         {@link android.provider.ContactsContract.CommonDataKinds.StructuredName}. Lin lc th
    245         ch c mt hng thuc loi ny trong bng {@link android.provider.ContactsContract.Data}.
    246     </li>
    247     <li>
    248         <strong>Ch :</strong>  s dng d liu ti khon ca chnh bn trong mt hng lin lc th, trc tin d liu
    249         phi c ng k vi {@link android.accounts.AccountManager}.  lm iu ny, hy nhc
    250         ngi dng thm loi ti khon v tn ti khon ca chng vo danh sch ti khon. Nu bn khng
    251         lm vy, Trnh cung cp Danh b s t ng xa hng lin lc th ca bn.
    252         <p>
    253             V d, nu bn mun ng dng ca mnh duy tr d liu danh b cho dch v da trn nn web ca mnh
    254             vi min {@code com.example.dataservice}, v ti khon ca ngi dng cho dch v ca bn
    255             l {@code becky.sharp (a] dataservice.example.com}, trc tin, ngi dng phi thm
    256             "loi" ti khon ({@code com.example.dataservice}) v "tn" ti khon
    257             ({@code becky.smart (a] dataservice.example.com}) trc khi ng dng ca bn c th thm hng lin lc th.
    258             Bn c th gii thch yu cu ny vi ngi dng bng ti liu, hoc bn c th nhc
    259             ngi dng thm loi v tn ny, hoc c hai. Loi ti khon v tn ti khon
    260             c trnh by chi tit hn trong phn sau.
    261     </li>
    262 </ul>
    263 <h3 id="RawContactsExample">Cc ngun d liu lin lc th</h3>
    264 <p>
    265      hiu cch hot ng ca lin lc th, hy xt ngi dng "Emily Dickinson", c ta c ba ti khon
    266     ngi dng sau c xc nh trn thit b ca mnh:
    267 </p>
    268 <ul>
    269     <li><code>emily.dickinson (a] gmail.com</code></li>
    270     <li><code>emilyd (a] gmail.com</code></li>
    271     <li>Ti khon Twitter "belle_of_amherst"</li>
    272 </ul>
    273 <p>
    274     Ngi dng ny  kch hot <em>ng b Danh b</em> cho c ba ti khon ny trong ci t
    275     <em>Ti khon</em>.
    276 </p>
    277 <p>
    278     Gi s Emily Dickinson m mt ca s trnh duyt, ng nhp vo Gmail bng ti khon
    279     <code>emily.dickinson (a] gmail.com</code>, m
    280     Danh b, v thm "Thomas Higginson". Sau , c ng nhp vo Gmail bng ti khon
    281     <code>emilyd (a] gmail.com</code> v gi mt e-mail ti "Thomas Higginson", lm vy s t ng
    282     thm ngi ny lm mt lin lc. C y cng theo di "colonel_tom" (ID Twitter ca Thomas Higginson) trn
    283     Twitter.
    284 </p>
    285 <p>
    286     Trnh cung cp Danh b s to ba lin lc th do kt qu ca vic lm ny:
    287 </p>
    288 <ol>
    289     <li>
    290         Mt lin lc th cho "Thomas Higginson" lin kt vi <code>emily.dickinson (a] gmail.com</code>.
    291         Loi ti khon ngi dng l Google.
    292     </li>
    293     <li>
    294         Mt lin lc th th hai cho "Thomas Higginson" lin kt vi <code>emilyd (a] gmail.com</code>.
    295         Loi ti khon ngi dng cng l Google. C mt lin lc th th hai ngay c khi
    296         tn ging vi mt tn trc , v ngi ny  c thm cho mt
    297         ti khon ngi dng khc.
    298     </li>
    299     <li>
    300         Mt lin lc th th ba cho "Thomas Higginson" lin kt vi "belle_of_amherst". Loi ti khon ngi dng
    301         l Twitter.
    302     </li>
    303 </ol>
    304 <h2 id="DataBasics">D liu</h2>
    305 <p>
    306     Nh  cp trc , d liu ca mt lin lc th c lu gi trong mt hng
    307     {@link android.provider.ContactsContract.Data} c lin kt vi gi tr
    308     <code>_ID</code> ca lin lc th. iu ny cho php mt lin lc th c nhiu thc th cng loi
    309     d liu chng hn nh a ch e-mail hay s in thoi. V d, nu
    310     "Thomas Higginson" ca {@code emilyd (a] gmail.com}  (hng lin lc th cho Thomas Higginson
    311     lin kt vi ti khon Google <code>emilyd (a] gmail.com</code>) c mt a ch e-mail nh l
    312     <code>thigg (a] gmail.com</code> v mt a ch e-mail c quan l
    313     <code>thomas.higginson (a] gmail.com</code>, Trnh cung cp Danh b s lu tr hai hng a ch e-mail 
    314     v lin kt c hai vi lin lc th.
    315 </p>
    316 <p>
    317       rng cc loi d liu khc nhau c lu gi trong mt bng ny. Cc hng tn hin th,
    318     s in thoi, e-mail, a ch gi th, nh v chi tit trang web u c tm thy trong bng
    319     {@link android.provider.ContactsContract.Data}.  gip qun l iu ny, bng
    320     {@link android.provider.ContactsContract.Data} c mt s ct c tn m t,
    321     v cc ct cn li c tn chung. Cc ni dung ca ct tn m t c cng  ngha
    322     khng ph thuc vo loi d liu trong hng, trong khi ni dung ca ct tn chung c
    323      ngha khc nhau ty vo loi d liu.
    324 </p>
    325 <h3 id="DescriptiveColumns">Tn ct m t</h3>
    326 <p>
    327     Mt s v d v tn ct m t l:
    328 </p>
    329 <dl>
    330     <dt>
    331         {@link android.provider.ContactsContract.Data#RAW_CONTACT_ID}
    332     </dt>
    333     <dd>
    334         Gi tr ca ct <code>_ID</code> ca lin lc th i vi d liu ny.
    335     </dd>
    336     <dt>
    337         {@link android.provider.ContactsContract.Data#MIMETYPE}
    338     </dt>
    339     <dd>
    340         Loi d liu c lu gi trong hng ny, c th hin di dng mt kiu MIME ty chnh. Trnh cung cp Danh b
    341         s dng cc kiu MIME c nh ngha trong lp con ca
    342         {@link android.provider.ContactsContract.CommonDataKinds}. Cc kiu MIME l ngun m,
    343         v c th c s dng bi bt k ng dng hay trnh iu hp ng b no hot ng vi Trnh cung cp Danh b.
    344     </dd>
    345     <dt>
    346         {@link android.provider.ContactsContract.DataColumns#IS_PRIMARY}
    347     </dt>
    348     <dd>
    349         Nu kiu hng d liu ny c th xy ra nhiu hn mt ln i vi mt lin lc th, ct
    350         {@link android.provider.ContactsContract.DataColumns#IS_PRIMARY} s gn c
    351         hng d liu cha d liu s cp cho kiu . V d, nu
    352         ngi dng nhn gi mt s in thoi cho mt lin lc v chn <strong>t mc nh</strong>,
    353         khi  hng {@link android.provider.ContactsContract.Data} cha s 
    354         c ct tng ng {@link android.provider.ContactsContract.DataColumns#IS_PRIMARY} c t thnh mt
    355         gi tr khc 0.
    356     </dd>
    357 </dl>
    358 <h3 id="GenericColumns">Tn ct chung</h3>
    359 <p>
    360     C 15 ct chung c t tn <code>DATA1</code> thng qua
    361     <code>DATA15</code> thng c sn v thm bn ct
    362     chung <code>SYNC1</code> thng qua <code>SYNC4</code> m ch c s dng bi trnh iu hp
    363     ng b. Cc hng s tn ct chung lun c tc dng, khng ph thuc vo loi
    364     d liu m hng  cha.
    365 </p>
    366 <p>
    367     Ct <code>DATA1</code> c nh ch mc.  Trnh cung cp Danh b lun s dng ct ny cho
    368     d liu m trnh cung cp k vng s l i tng truy vn thng xuyn nht. V d,
    369     trong mt hng e-mail, ct ny cha a ch e-mail thc s.
    370 </p>
    371 <p>
    372     Theo quy c, ct <code>DATA15</code> c dnh  lu gi d liu Binary Large Object
    373     (BLOB) chng hn nh hnh thu nh ca nh.
    374 </p>
    375 <h3 id="TypeSpecificNames">Tn ct theo kiu</h3>
    376 <p>
    377      to iu kin lm vic vi cc ct i vi mt kiu hng c th, Trnh cung cp Danh b
    378     cng cung cp cc hng s tn ct theo kiu, c nh ngha trong cc lp con ca
    379     {@link android.provider.ContactsContract.CommonDataKinds}. Cc hng s ch cp mt
    380     tn hng s khc cho cng tn ct, iu ny gip bn truy cp d liu trong mt hng thuc
    381     mt kiu c th.
    382 </p>
    383 <p>
    384     V d, lp {@link android.provider.ContactsContract.CommonDataKinds.Email} nh ngha
    385     cc hng s tn ct theo kiu cho mt hng {@link android.provider.ContactsContract.Data} m
    386     c kiu MIME
    387     {@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_ITEM_TYPE
    388     Email.CONTENT_ITEM_TYPE}. Lp cha hng s
    389     {@link android.provider.ContactsContract.CommonDataKinds.Email#ADDRESS} cho ct
    390     a ch e-mail. Gi tr thc s ca
    391     {@link android.provider.ContactsContract.CommonDataKinds.Email#ADDRESS} l "data1", gi tr ny
    392     ging ht nh tn chung ca ct.
    393 </p>
    394 <p class="caution">
    395     <strong>Ch :</strong> Khng c thm d liu ty chnh ca chnh bn vo bng
    396     {@link android.provider.ContactsContract.Data} bng cch s dng mt hng c mt trong cc kiu MIME c xc nh trc
    397     ca trnh cung cp. Nu lm vy, bn c th lm mt d liu hoc khin trnh cung cp
    398     gp trc trc. V d, bn khng nn thm mt hng c kiu MIME
    399     {@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_ITEM_TYPE
    400     Email.CONTENT_ITEM_TYPE} m cha tn ngi dng thay v a ch e-mail trong ct
    401     <code>DATA1</code>. Nu s dng kiu MIME ty chnh ca mnh cho hng, khi  bn c t do
    402     nh ngha tn ct theo kiu ca chnh mnh v s dng cc ct theo cch bn mun.
    403 </p>
    404 <p>
    405     Hnh 2 minh ha cch cc ct m t v ct d liu xut hin trong hng
    406     {@link android.provider.ContactsContract.Data}, v cch m tn ct theo kiu "ph ln"
    407    tn ct chung
    408 </p>
    409 <img src="{@docRoot}images/providers/data_columns.png" alt="How type-specific column names map to generic column names" height="311" id="figure2" />
    410 <p class="img-caption">
    411   <strong>Hnh 2.</strong> Tn ct theo kiu v tn ct chung.
    412 </p>
    413 <h3 id="ColumnMaps">Lp tn ct theo kiu</h3>
    414 <p>
    415     Bng 2 lit k cc lp tn ct theo kiu thng c s dng nht:
    416 </p>
    417 <p class="table-caption" id="table2">
    418   <strong>Bng 2.</strong> Lp tn ct theo kiu</p>
    419 <table>
    420   <tr>
    421     <th scope="col">Lp nh x</th>
    422     <th scope="col">Kiu d liu</th>
    423     <th scope="col">Lu </th>
    424   </tr>
    425   <tr>
    426     <td>{@link android.provider.ContactsContract.CommonDataKinds.StructuredName}</td>
    427     <td>D liu tn ca lin lc th lin kt vi hng d liu ny.</td>
    428     <td>Mt lin lc th ch c mt trong nhng hng ny.</td>
    429   </tr>
    430   <tr>
    431     <td>{@link android.provider.ContactsContract.CommonDataKinds.Photo}</td>
    432     <td>nh chnh ca lin lc th c lin kt vi hng d liu ny.</td>
    433     <td>Mt lin lc th ch c mt trong nhng hng ny.</td>
    434   </tr>
    435   <tr>
    436     <td>{@link android.provider.ContactsContract.CommonDataKinds.Email}</td>
    437     <td>a ch e-mail ca lin lc th c lin kt vi hng d liu ny.</td>
    438     <td>Mt lin lc th c th c nhiu a ch e-mail.</td>
    439   </tr>
    440   <tr>
    441     <td>{@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal}</td>
    442     <td>a ch cng ca lin lc th c lin kt vi hng d liu ny.</td>
    443     <td>Mt lin lc th c th c nhiu a ch cng.</td>
    444   </tr>
    445   <tr>
    446     <td>{@link android.provider.ContactsContract.CommonDataKinds.GroupMembership}</td>
    447     <td>M nh danh lin kt lin lc th vi mt trong cc nhm trong Trnh cung cp Danh b.</td>
    448     <td>
    449         Nhm l mt tnh nng ty chn ca loi ti khon v tn ti khon. Chng c m t
    450         chi tit hn trong phn <a href="#Groups">Nhm lin lc</a>.
    451     </td>
    452   </tr>
    453 </table>
    454 <h3 id="ContactBasics">Danh b</h3>
    455 <p>
    456     Trnh cung cp Danh b kt hp cc hng lin lc th gia tt c cc loi ti khon v tn ti khon
    457      to thnh mt <strong>lin lc</strong>. iu ny to iu kin  hin th v sa i tt c d liu m mt
    458     ngi dng  thu thp cho mt ngi. Trnh cung cp Danh b qun l vic to cc hng lin lc mi
    459     v tng hp cc lin lc th vi hng lin lc hin c. ng dng ln
    460     trnh iu hp ng b u khng c cho php thm lin lc v mt s ct trong mt hng lin lc l ct ch c.
    461 </p>
    462 <p class="note">
    463     <strong>Lu :</strong> Nu bn c gng thm mt lin lc vo Trnh cung cp Danh b c mt
    464     {@link android.content.ContentResolver#insert(Uri,ContentValues) insert()}, bn s gp
    465     li ngoi l {@link java.lang.UnsupportedOperationException}. Nu bn c gng cp nht mt ct
    466     m c lit k l "ch c," cp nht s b b qua.
    467 </p>
    468 <p>
    469     Trnh cung cp Danh b to mt lin lc mi  hi p li vic thm mt lin lc th mi
    470     khng khp vi bt k lin lc no hin c. Trnh cung cp cng lm vy nu d liu
    471     ca mt lin lc th hin c thay i sao cho n khng cn khp vi lin lc m trc 
    472     n c gn vi. Nu mt ng dng hoc trnh iu hp ng b to mt lin lc th mi m
    473     <em>khp</em> vi mt lin lc hin ti, lin lc th mi s c tng hp vo lin lc
    474     hin c.
    475 </p>
    476 <p>
    477     Trnh cung cp Danh b s lin kt mt hng lin lc vi cc hng lin lc th ca n bng ct
    478     <code>_ID</code> ca hng lin lc  trong bng {@link android.provider.ContactsContract.Contacts Contacts}
    479 . Ct <code>CONTACT_ID</code> ca bng lin lc th
    480     {@link android.provider.ContactsContract.RawContacts} cha cc gi tr <code>_ID</code> cho
    481     cc hng lin lc lin kt vi tng hng lin lc th.
    482 </p>
    483 <p>
    484     Bng {@link android.provider.ContactsContract.Contacts} cng c ct
    485     {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} m l mt lin kt
    486     "c nh" vi hng lin lc . V Trnh cung cp Danh b t ng duy tr
    487     cc lin lc, n c th thay i gi tr {@code android.provider.BaseColumns#_ID} ca mt hng lin lc
    488     hi p li mt s tng hp hoc ng b. Ngay c khi iu ny xy ra, URI ni dung
    489     {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} kt hp vi
    490     {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} ca lin lc s vn
    491     ch v hng lin lc , v th bn c th s dng
    492     {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY}
    493      duy tr cc lin kt n lin lc "yu thch", v.v. Ct ny c nh dng ring khng
    494     lin quan ti nh dng ca ct {@code android.provider.BaseColumns#_ID}.
    495 </p>
    496 <p>
    497     Hnh 3 minh ha mi lin quan gia ba bng chnh ny vi nhau.
    498 </p>
    499 <img src="{@docRoot}images/providers/contacts_tables.png" alt="Contacts provider main tables" height="514" id="figure4" />
    500 <p class="img-caption">
    501   <strong>Hnh 3.</strong> Mi quan h gia cc bng Danh b, Lin lc Th, v Chi tit.
    502 </p>
    503 <h2 id="Sources">D liu t Trnh iu hp ng b</h2>
    504 <p>
    505     Ngi dng nhp d liu danh b trc tip vo thit b, nhng d liu cng i n Trnh cung cp
    506     Danh b t cc dch v web thng qua <strong>trnh iu hp ng b</strong>, gip t ng
    507     chuyn d liu gia thit b v cc dch v. Trnh iu hp ng b chy ngm
    508     di s kim sot ca h thng, v chng gi cc phng php {@link android.content.ContentResolver} 
    509     qun l d liu.
    510 </p>
    511 <p>
    512     Trong Android, dch v web m mt trnh iu hp ng b lm vic cng s c xc nh bng mt loi ti khon.
    513     Mi trnh iu hp ng b lm vic vi mt loi ti khon, nhng n c th h tr nhiu tn ti khon cho
    514     loi . Cc loi ti khon v tn ti khon c m t s qua trong phn
    515     <a href="#RawContactsExample">Cc ngun d liu lin lc th</a>. Cc nh ngha sau trnh by
    516     chi tit hn v m t mi lin quan gia loi v tn ti khon vi cc trnh iu hp ng b v dch v.
    517 </p>
    518 <dl>
    519     <dt>
    520         Loi ti khon
    521     </dt>
    522     <dd>
    523         Xc nh mt dch v m ngi dng  lu gi d liu trong . Trong phn ln thi gian, ngi dng phi
    524         xc thc dch v. V d, Google Contacts l mt loi ti khon c xc nh
    525         bi m <code>google.com</code>. Gi tr ny tng ng vi loi ti khon c s dng bi
    526         {@link android.accounts.AccountManager}.
    527     </dd>
    528     <dt>
    529         Tn ti khon
    530     </dt>
    531     <dd>
    532         Xc nh mt ti khon hoc ng nhp c th cho mt loi ti khon. Ti khon Google Contacts
    533         ging nh ti khon Google, chng c mt a ch e-mail lm tn ti khon.
    534         Cc dch v khc c th s dng tn ngi dng l mt t hoc id ch s.
    535     </dd>
    536 </dl>
    537 <p>
    538     Loi ti khon khng nht thit phi duy nht. Mt ngi dng c th cu hnh nhiu ti khon Google Contacts
    539     v ti xung d liu ca chng vo Trnh cung cp Danh b; iu ny c th xy ra nu ngi dng c mt tp hp
    540     cc lin lc c nhn cho mt tn ti khon c nhn, v mt tp hp khc cho c quan. Tn ti khon thng
    541     l duy nht. Cng nhau, chng xc nh mt dng d liu c th gia Trnh cung cp Danh b v
    542     mt dch v bn ngoi.
    543 </p>
    544 <p>
    545     Nu mun chuyn d liu t dch v ca bn sang Trnh cung cp Danh b, bn cn ghi
    546     vo trnh iu hp ng b ca chnh mnh. iu ny c m t chi tit hn trong phn
    547     <a href="#SyncAdapters">Trnh iu hp ng b Trnh cung cp Danh b</a>.
    548 </p>
    549 <p>
    550     Hnh 4 minh ha cch m Trnh cung cp Danh b ph hp vi dng d liu
    551     v con ngi. Trong hp c nh du "trnh iu hp ng b," mi trnh iu hp c ghi nhn theo loi ti khon ca n.
    552 </p>
    553 <img src="{@docRoot}images/providers/ContactsDataFlow.png" alt="Flow of data about people" height="252" id="figure5" />
    554 <p class="img-caption">
    555   <strong>Hnh 4.</strong> Lung d liu ca Trnh cung cp Danh b.
    556 </p>
    557 <h2 id="Permissions">Quyn c Yu cu</h2>
    558 <p>
    559     Nhng ng dng mun truy cp Trnh cung cp Danh b phi yu cu cc quyn
    560     sau:
    561 </p>
    562 <dl>
    563     <dt>Quyn truy cp c vo mt hoc nhiu bng</dt>
    564     <dd>
    565         {@link android.Manifest.permission#READ_CONTACTS}, c quy nh trong
    566         <code>AndroidManifest.xml</code> vi phn t
    567         <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">
    568         &lt;uses-permission&gt;</a></code> l
    569         <code>&lt;uses-permission android:name="android.permission.READ_CONTACTS"&gt;</code>.
    570     </dd>
    571     <dt>Quyn truy cp ghi vo mt hoc nhiu bng</dt>
    572     <dd>
    573         {@link android.Manifest.permission#WRITE_CONTACTS}, c quy nh trong
    574         <code>AndroidManifest.xml</code> vi phn t
    575         <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">
    576         &lt;uses-permission&gt;</a></code> l
    577         <code>&lt;uses-permission android:name="android.permission.WRITE_CONTACTS"&gt;</code>.
    578     </dd>
    579 </dl>
    580 <p>
    581     Nhng quyn ny khng m rng sang d liu h s ngi dng. H s ngi dng v cc quyn
    582     c yu cu c  cp trong phn sau,
    583     <a href="#UserProfile">H s Ngi dng</a>.
    584 </p>
    585 <p>
    586     Nh rng d liu danh b ca ngi dng l d liu c nhn v nhy cm. Ngi dng quan tm v
    587     quyn ring t ca h, v th h khng mun cc ng dng thu thp d liu v mnh hoc danh b ca mnh.
    588     Nu khng r rng v l do bn cn quyn truy cp d liu danh b ca h, h c th cho
    589     ng dng ca bn nh gi thp hoc t chi ci t ng dng.
    590 </p>
    591 <h2 id="UserProfile">H s Ngi dng</h2>
    592 <p>
    593     Bng {@link android.provider.ContactsContract.Contacts} c mt hng n cha
    594     d liu h s cho ngi dng ca thit b. D liu ny m t <code>user</code> ca thit b ch khng phi
    595     ca mt trong cc lin lc ca ngi dng. Hng lin lc h s c lin kt vi hng
    596     lin lc th i vi tng h thng s dng h s.
    597     Mi hng lin lc th ca h s c th c nhiu hng d liu. Cc hng s  truy cp h s
    598     ngi dng c sn trong lp {@link android.provider.ContactsContract.Profile}.
    599 </p>
    600 <p>
    601     Truy cp h s ngi dng i hi phi c cc quyn c bit. Ngoi cc quyn
    602     {@link android.Manifest.permission#READ_CONTACTS} v
    603     {@link android.Manifest.permission#WRITE_CONTACTS} cn  c v ghi, truy cp
    604     h s ngi dng cn yu cu quyn {@code android.Manifest.permission#READ_PROFILE} v
    605     {@code android.Manifest.permission#WRITE_PROFILE} tng ng cho quyn truy cp c v
    606     ghi.
    607 </p>
    608 <p>
    609     Nh rng bn nn coi h s ca mt ngi dng l ni dung nhy cm. Quyn
    610     {@code android.Manifest.permission#READ_PROFILE} cho php bn truy cp d liu xc nh c nhn
    611     ca ngi dng thit b. Chc chn phi ni cho ngi dng bit l do ti sao
    612     bn cn cc quyn truy cp h s ngi dng trong phn m t ng dng ca mnh.
    613 </p>
    614 <p>
    615      truy xut hng lin lc cha h s ca ngi dng,
    616     hy gi {@link android.content.ContentResolver#query(Uri,String[], String, String[], String)
    617     ContentResolver.query()}. t URI ni dung thnh
    618     {@link android.provider.ContactsContract.Profile#CONTENT_URI} v khng cung cp bt k
    619     tiu ch la chn no. Bn cng c th s dng URI ni dung ny lm URI c s  truy xut cc lin lc th
    620     hoc d liu cho h s. V d, on m HTML ny truy xut d liu cho h s:
    621 </p>
    622 <pre>
    623 // Sets the columns to retrieve for the user profile
    624 mProjection = new String[]
    625     {
    626         Profile._ID,
    627         Profile.DISPLAY_NAME_PRIMARY,
    628         Profile.LOOKUP_KEY,
    629         Profile.PHOTO_THUMBNAIL_URI
    630     };
    631 
    632 // Retrieves the profile from the Contacts Provider
    633 mProfileCursor =
    634         getContentResolver().query(
    635                 Profile.CONTENT_URI,
    636                 mProjection ,
    637                 null,
    638                 null,
    639                 null);
    640 </pre>
    641 <p class="note">
    642     <strong>Lu :</strong> Nu bn truy xut nhiu hng lin lc v mun xc nh xem mt trong s chng c phi
    643     l h s ngi dng khng, hy kim tra ct
    644     {@link android.provider.ContactsContract.ContactsColumns#IS_USER_PROFILE} ca hng. Ct ny
    645     c t thnh "1" nu lin lc l h s ngi dng.
    646 </p>
    647 <h2 id="ContactsProviderMetadata">Siu d liu Trnh cung cp Danh b</h2>
    648 <p>
    649     Trnh cung cp Danh b qun l d liu theo di trng thi ca d liu danh b trong
    650     kho lu gi. Siu d liu v kho lu gi ny c lu gi  nhiu ni khc nhau, bao gm
    651     cc hng bng Lin lc Th, D liu, v Danh b, bng
    652     {@link android.provider.ContactsContract.Settings}, v bng
    653     {@link android.provider.ContactsContract.SyncState}. Bng sau y cho bit
    654     nh hng ca tng mc trong siu d liu ny:
    655 </p>
    656 <p class="table-caption" id="table3">
    657   <strong>Bng 3.</strong> Siu d liu trong Trnh cung cp Danh b</p>
    658 <table>
    659     <tr>
    660         <th scope="col">Bng</th>
    661         <th scope="col">Ct</th>
    662         <th scope="col">Gi tr</th>
    663         <th scope="col"> ngha</th>
    664     </tr>
    665     <tr>
    666         <td rowspan="2">{@link android.provider.ContactsContract.RawContacts}</td>
    667         <td rowspan="2">{@link android.provider.ContactsContract.SyncColumns#DIRTY}</td>
    668         <td>"0" - khng thay i k t ln ng b cui cng.</td>
    669         <td rowspan="2">
    670             nh du cc lin lc th  c thay i trn thit b v phi c ng b tr li
    671             my ch. Gi tr c t t ng bi Trnh cung cp Danh b khi cc ng dng
    672             Android cp nht mt hng.
    673             <p>
    674                 Cc trnh iu hp ng b sa i bng lin lc th hoc d liu nn lun ni
    675                 xu {@link android.provider.ContactsContract#CALLER_IS_SYNCADAPTER} vi
    676                 URI ni dung m chng s dng. Lm vy s ngn khng cho trnh cung cp nh du hng l khng tt.
    677                 Nu khng, cc sa i trnh iu hp ng b xem nh sa i cc b v c
    678                 gi ti my ch, ngay c khi my ch l ngun sa i.
    679             </p>
    680         </td>
    681     </tr>
    682     <tr>
    683             <td>"1" -  thay i k t ln ng b cui cng, cn c ng b li my ch.</td>
    684     </tr>
    685     <tr>
    686         <td>{@link android.provider.ContactsContract.RawContacts}</td>
    687         <td>{@link android.provider.ContactsContract.SyncColumns#VERSION}</td>
    688         <td>S phin bn ca hng ny.</td>
    689         <td>
    690             Trnh cung cp Danh b t ng tng dn gi tr ny bt c khi no hng hoc
    691             d liu c lin quan ca hng thay i.
    692         </td>
    693     </tr>
    694     <tr>
    695         <td>{@link android.provider.ContactsContract.Data}</td>
    696         <td>{@link android.provider.ContactsContract.DataColumns#DATA_VERSION}</td>
    697         <td>S phin bn ca hng ny.</td>
    698         <td>
    699             Trnh cung cp Danh b t ng tng dn gi tr ny bt c khi no hng d liu
    700             b thay i.
    701         </td>
    702     </tr>
    703     <tr>
    704         <td>{@link android.provider.ContactsContract.RawContacts}</td>
    705         <td>{@link android.provider.ContactsContract.SyncColumns#SOURCE_ID}</td>
    706         <td>
    707             Mt xu gi tr xc nh duy nht lin lc th ny cho ti khon m
    708             n c to trong .
    709         </td>
    710         <td>
    711             Khi mt trnh iu hp ng b to mt lin lc th mi, ct ny nn c t thnh
    712             ID duy nht ca my ch dnh cho lin lc th . Khi mt ng dng Android to mt lin lc th
    713             mi, ng dng  s  trng ct ny. iu ny bo hiu vi trnh iu hp
    714             ng b rng n nn to mt lin lc th mi trn my ch, v ly mt
    715             gi tr cho {@link android.provider.ContactsContract.SyncColumns#SOURCE_ID}.
    716             <p>
    717                 C th, id ngun phi l <strong>duy nht</strong> i vi tng loi ti khon
    718                 v nn n nh gia cc ln ng b:
    719             </p>
    720                 <ul>
    721                     <li>
    722                         Duy nht: Mi lin lc th i vi mt ti khon phi c id ngun ring ca mnh. Nu khng
    723                         thi hnh iu ny, bn s gy ra s c trong ng dng danh b.
    724                           rng hai lin lc th i vi cng <em>loi</em> ti khon c th c
    725                         cng id ngun. V d, lin lc th "Thomas Higginson" i vi
    726                         ti khon {@code emily.dickinson (a] gmail.com} c cho php c cng id ngun
    727                         nh lin lc th "Thomas Higginson" i vi ti khon
    728                         {@code emilyd (a] gmail.com}.
    729                     </li>
    730                     <li>
    731                         n nh: Id ngun l mt b phn c nh ca d liu t dch v trc tuyn i vi
    732                         lin lc th. V d, nu ngi dng xa Lu tr Danh b khi
    733                         ci t ng dng v ng b li, cc lin lc th c khi phc s c cng
    734                         id ngun nh trc. Nu bn khng thi hnh iu ny, cc li tt s dng
    735                         hot ng.
    736                     </li>
    737                 </ul>
    738         </td>
    739     </tr>
    740     <tr>
    741         <td rowspan="2">{@link android.provider.ContactsContract.Groups}</td>
    742         <td rowspan="2">{@link android.provider.ContactsContract.GroupsColumns#GROUP_VISIBLE}</td>
    743         <td>"0" - Cc lin lc trong nhm ny khng nn c hin th trong UI ng dng Android.</td>
    744         <td>
    745             Ct ny dnh cho tnh tng thch vi cc my ch m cho php ngi dng n cc lin lc trong
    746             mt s nhm.
    747         </td>
    748     </tr>
    749     <tr>
    750         <td>"1" - Cc lin lc trong nhm ny c cho php hin th trong UI ng dng.</td>
    751     </tr>
    752     <tr>
    753         <td rowspan="2">{@link android.provider.ContactsContract.Settings}</td>
    754         <td rowspan="2">
    755             {@link android.provider.ContactsContract.SettingsColumns#UNGROUPED_VISIBLE}</td>
    756         <td>
    757             "0" - i vi ti khon v loi ti khon ny, nhng lin lc khng thuc v nhm
    758             c n i vi UI ng dng Android.
    759         </td>
    760         <td rowspan="2">
    761             Theo mc nh, cc lin lc c hin th nu khng c lin lc th no ca chng thuc v mt nhm
    762             (T cch thnh vin nhm i vi mt lin lc th c th hin bng mt hoc nhiu hng
    763             {@link android.provider.ContactsContract.CommonDataKinds.GroupMembership} trong
    764             bng {@link android.provider.ContactsContract.Data}).
    765             Bng cch t c ny trong hng bng {@link android.provider.ContactsContract.Settings} i vi
    766             mt loi ti khon v ti khon, bn c th buc nhng lin lc khng c nhm phi hin th.
    767             Mt cng dng ca c ny  l  hin th lin lc t cc my ch khng s dng nhm.
    768         </td>
    769     </tr>
    770     <tr>
    771         <td>
    772             "1" - i vi ti khon v loi ti khon ny, nhng lin lc khng thuc v nhm
    773             s c hin th i vi UI ng dng.
    774         </td>
    775 
    776     </tr>
    777     <tr>
    778         <td>{@link android.provider.ContactsContract.SyncState}</td>
    779         <td>(tt c)</td>
    780         <td>
    781             S dng bng ny  lu gi siu d liu cho trnh iu hp ng b ca bn.
    782         </td>
    783         <td>
    784             Vi bng ny, bn c th lu gi trng thi ng b v cc d liu khc lin quan ti ng b mt cch lu di
    785             trn thit b.
    786         </td>
    787     </tr>
    788 </table>
    789 <h2 id="Access">Truy cp Trnh cung cp Danh b</h2>
    790 <p>
    791     Phn ny m t cc hng dn v truy cp d liu t Trnh cung cp Danh b, tp trung vo nhng
    792     ni dung sau:
    793 </p>
    794 <ul>
    795     <li>
    796         Truy vn thc th.
    797     </li>
    798     <li>
    799         Sa i hng lot.
    800     </li>
    801     <li>
    802         Truy xut v sa i bng  nh.
    803     </li>
    804     <li>
    805         Ton vn d liu.
    806     </li>
    807 </ul>
    808 <p>
    809     Thc hin sa i t mt trnh iu hp ng b cng c  cp chi tit hn trong phn
    810     <a href="#SyncAdapters">Trnh iu hp ng b Trnh cung cp Danh b</a>.
    811 </p>
    812 <h3 id="Entities">Truy vn thc th</h3>
    813 <p>
    814     V cc bng ca Trnh cung cp Danh b c t chc theo mt phn cp, thng s hu ch nu
    815     truy xut mt hng v tt c hng "con" c lin kt vi n. V d,  hin th
    816     tt c thng tin cho mt ngi, bn c th mun truy xut tt c hng
    817     {@link android.provider.ContactsContract.RawContacts} i vi mt hng
    818     {@link android.provider.ContactsContract.Contacts} n, hoc tt c hng
    819     {@link android.provider.ContactsContract.CommonDataKinds.Email} i vi mt hng
    820     {@link android.provider.ContactsContract.RawContacts} n.  to iu kin cho iu ny, Trnh cung cp
    821     Danh b s cung cp cc cu trc <strong>thc th</strong> ng vai tr nh lin kt c s d liu
    822     gia cc bng.
    823 </p>
    824 <p>
    825     Thc th ging nh mt bng bao gm cc ct c chn t mt bng m v bng con ca n.
    826     Khi bn truy vn mt thc th, bn cung cp mt d tho v cc tiu ch da trn cc ct
    827     c sn t thc th. Kt qu l mt {@link android.database.Cursor} trong  cha
    828     mt hng cho tng hng bng con c truy xut. V d, nu bn truy vn
    829     {@link android.provider.ContactsContract.Contacts.Entity} cho mt tn lin lc
    830     v tt c hng {@link android.provider.ContactsContract.CommonDataKinds.Email} i vi tt c
    831     lin lc th cho tn , bn s nhn li mt {@link android.database.Cursor} cha mt hng
    832     cho mi hng {@link android.provider.ContactsContract.CommonDataKinds.Email}.
    833 </p>
    834 <p>
    835     Cc thc th s n gin ha vic truy vn. Bng cch s dng mt thc th, bn c th truy xut ngay lp tc tt c d liu danh b cho mt
    836     lin lc hoc lin lc th, thay v phi truy vn bng m trc  nhn mt
    837     ID, v ri phi truy xut bng con bng ID . ng thi, Trnh cung cp Danh b x l
    838     mt truy vn i vi mt thc th trong mt giao tc n, iu ny m bo rng d liu c truy xut s c
    839     nht qun trong ni b.
    840 </p>
    841 <p class="note">
    842     <strong>Lu :</strong> Mt thc th thng khng cha tt c ct ca bng m v
    843     bng con. Nu bn c gng lm vic vi mt tn ct khng c trong danh sch cc hng s tn ct
    844     i vi thc th , bn s nhn c mt {@link java.lang.Exception}.
    845 </p>
    846 <p>
    847     on m HTML sau cho bit cch truy xut tt c hng lin lc th cho mt lin lc. on m HTML
    848     l b phn ca mt ng dng ln hn c hai hot ng, "chnh" v "chi tit". Hot ng chnh
    849     hin th mt danh sch cc hng lin lc; khi ngi dng chn mt hng, hot ng s gi ID ca hng ti hot ng
    850     chi tit. Hot ng chi tit s dng {@link android.provider.ContactsContract.Contacts.Entity}
    851      hin th tt c hng d liu t tt c lin lc th c lin kt vi lin lc
    852      chn.
    853 </p>
    854 <p>
    855     on m HTML ny c ly t hot ng "chi tit":
    856 </p>
    857 <pre>
    858 ...
    859     /*
    860      * Appends the entity path to the URI. In the case of the Contacts Provider, the
    861      * expected URI is content://com.google.contacts/#/entity (# is the ID value).
    862      */
    863     mContactUri = Uri.withAppendedPath(
    864             mContactUri,
    865             ContactsContract.Contacts.Entity.CONTENT_DIRECTORY);
    866 
    867     // Initializes the loader identified by LOADER_ID.
    868     getLoaderManager().initLoader(
    869             LOADER_ID,  // The identifier of the loader to initialize
    870             null,       // Arguments for the loader (in this case, none)
    871             this);      // The context of the activity
    872 
    873     // Creates a new cursor adapter to attach to the list view
    874     mCursorAdapter = new SimpleCursorAdapter(
    875             this,                        // the context of the activity
    876             R.layout.detail_list_item,   // the view item containing the detail widgets
    877             mCursor,                     // the backing cursor
    878             mFromColumns,                // the columns in the cursor that provide the data
    879             mToViews,                    // the views in the view item that display the data
    880             0);                          // flags
    881 
    882     // Sets the ListView's backing adapter.
    883     mRawContactList.setAdapter(mCursorAdapter);
    884 ...
    885 &#64;Override
    886 public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) {
    887 
    888     /*
    889      * Sets the columns to retrieve.
    890      * RAW_CONTACT_ID is included to identify the raw contact associated with the data row.
    891      * DATA1 contains the first column in the data row (usually the most important one).
    892      * MIMETYPE indicates the type of data in the data row.
    893      */
    894     String[] projection =
    895         {
    896             ContactsContract.Contacts.Entity.RAW_CONTACT_ID,
    897             ContactsContract.Contacts.Entity.DATA1,
    898             ContactsContract.Contacts.Entity.MIMETYPE
    899         };
    900 
    901     /*
    902      * Sorts the retrieved cursor by raw contact id, to keep all data rows for a single raw
    903      * contact collated together.
    904      */
    905     String sortOrder =
    906             ContactsContract.Contacts.Entity.RAW_CONTACT_ID +
    907             " ASC";
    908 
    909     /*
    910      * Returns a new CursorLoader. The arguments are similar to
    911      * ContentResolver.query(), except for the Context argument, which supplies the location of
    912      * the ContentResolver to use.
    913      */
    914     return new CursorLoader(
    915             getApplicationContext(),  // The activity's context
    916             mContactUri,              // The entity content URI for a single contact
    917             projection,               // The columns to retrieve
    918             null,                     // Retrieve all the raw contacts and their data rows.
    919             null,                     //
    920             sortOrder);               // Sort by the raw contact ID.
    921 }
    922 </pre>
    923 <p>
    924     Khi hon thnh vic ti, {@link android.app.LoaderManager} gi ra mt lnh gi li n
    925     {@link android.app.LoaderManager.LoaderCallbacks#onLoadFinished(Loader, D)
    926     onLoadFinished()}. Mt trong cc tham i n vi phng php ny l mt
    927     {@link android.database.Cursor} vi cc kt qu ca truy vn. Trong ng dng ca chnh mnh, bn c th nhn d liu
    928     t {@link android.database.Cursor} ny  hin th n hoc thao tc thm vi n.
    929 </p>
    930 <h3 id="Transactions">Sa i hng lot</h3>
    931 <p>
    932     Bt c khi no c th, bn nn chn, cp nht v xa d liu trong Trnh cung cp Danh b trong
    933     "ch  hng lot", bng cch to mt {@link java.util.ArrayList} ca cc i tng
    934     {@link android.content.ContentProviderOperation} v gi
    935     {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()}. V
    936     Trnh cung cp Danh b thc hin tt c thao tc trong mt
    937     {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} trong mt giao tc
    938     n, cc sa i ca bn s khng bao gi ra khi kho lu gi danh b mt cch
    939     khng nht qun. Sa i hng lot cng to iu kin cho vic chn mt lin lc th v d liu chi tit ca lin lc
    940     ti cng thi im.
    941 </p>
    942 <p class="note">
    943     <strong>Lu :</strong>  sa i mt lin lc th <em>n</em>, hy xt gi mt  nh ti
    944     ng dng danh b ca thit b thay v x l sa i trong ng dng ca bn.
    945     Vic lm ny c m t chi tit hn trong phn
    946     <a href="#Intents">Truy xut v sa i bng  nh</a>.
    947 </p>
    948 <h4>im kt qu</h4>
    949 <p>
    950     Sa i hng lot cha nhiu thao tc c th chn cc tin trnh khc,
    951     dn n tri nghim ngi dng tng th khng tt.  sp xp t chc tt c sa i m bn mun
    952     thc hin trong t danh sch ring nht c th, v ng thi ngn chng
    953     chn h thng, bn nn t cc <strong>im kt qu</strong> cho mt hoc nhiu thao tc.
    954     im kt qu l mt i tng {@link android.content.ContentProviderOperation} c gi tr
    955     {@link android.content.ContentProviderOperation#isYieldAllowed()} c t thnh
    956     <code>true</code>. Khi cc Trnh cung cp Danh b gp phi mt im kt qu, n tm dng cng vic 
    957     cho php cc tin trnh khc chy v ng giao tc hin ti. Khi trnh cung cp bt u li, n
    958     tip tc vi thao tc tip theo trong {@link java.util.ArrayList} v bt u mt giao tc
    959     mi.
    960 </p>
    961 <p>
    962     im kt qu dn n c nhiu hn mt giao tc trn mi lnh gi ti
    963     {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()}. V
    964     iu ny, bn nn t mt im kt qu cho thao tc cui cng i vi mt tp hp cc hng c lin quan.
    965     V d, bn nn t mt im kt qu cho thao tc cui cng trong mt tp hp m thm
    966     cc hng lin lc th v hng d liu lin kt ca chng, hoc thao tc cui cng i vi mt tp hp cc hng lin quan ti
    967     mt lin lc ring l.
    968 </p>
    969 <p>
    970     im kt qu cng l mt n v thao tc nguyn t. Tt c truy cp gia hai im kt qu s
    971     hoc thnh cng hoc tht bi nh mt n v ring l. Nu bn khng t bt k im kt qu no, thao tc
    972     nguyn t nh nht chnh l ton b lot thao tc. Nu s dng im kt qu, bn ngn cn
    973     cc thao tc lm gim hiu sut ca h thng, ng thi m bo rng mt tp con ca
    974     thao tc l tp nguyn t.
    975 </p>
    976 <h4>Tham chiu li sa i</h4>
    977 <p>
    978     Khi bn ang chn mt hng lin lc th mi v cc hng d liu lin kt ca n nh mt tp hp cc i tng
    979     {@link android.content.ContentProviderOperation}, bn phi lin kt cc hng d liu vi
    980     hng lin lc th bng cch chn gi tr
    981     {@code android.provider.BaseColumns#_ID} ca lin lc th lm gi tr
    982     {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID}. Tuy nhin, gi tr
    983     ny khng c sn khi bn ang to {@link android.content.ContentProviderOperation}
    984     cho hng d liu, v bn cha p dng
    985     {@link android.content.ContentProviderOperation} cho hng lin lc th.  khc phc iu ny,
    986     lp {@link android.content.ContentProviderOperation.Builder} c phng php
    987     {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()}.
    988     Phng php ny cho php bn chn hoc sa i mt ct bng
    989     kt qu ca mt thao tc trc .
    990 </p>
    991 <p>
    992     Phng php {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()}
    993     c hai tham i:
    994 </p>
    995     <dl>
    996         <dt>
    997             <code>key</code>
    998         </dt>
    999         <dd>
   1000             Kha ca mt cp kha-gi tr. Gi tr ca tham i ny nn l tn ca mt ct
   1001             trong bng m bn ang sa i.
   1002         </dd>
   1003         <dt>
   1004             <code>previousResult</code>
   1005         </dt>
   1006         <dd>
   1007             Ch mc da trn 0 ca mt gi tr trong mng i tng
   1008             {@link android.content.ContentProviderResult} t
   1009             {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()}. Khi
   1010             thao tc hng lot c p dng, kt qu ca mi thao tc c lu gi trong mt mng kt qu
   1011             trung gian. Gi tr <code>previousResult</code> l ch mc
   1012             ca mt trong nhng kt qu ny, n c truy xut v lu gi vi gi tr <code>key</code>
   1013 . iu ny cho php bn chn mt bn ghi lin lc th mi v nhn li gi tr
   1014             {@code android.provider.BaseColumns#_ID} ca n, ri thc hin mt "tham chiu ngc" v
   1015             gi tr  khi bn thm mt hng {@link android.provider.ContactsContract.Data}.
   1016             <p>
   1017                 Ton b mng kt qu c to khi bn ln u gi
   1018                 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()},
   1019                 vi kch c bng vi kch c ca {@link java.util.ArrayList} ca cc i tng
   1020                 {@link android.content.ContentProviderOperation} m bn cung cp. Tuy nhin, tt c
   1021                 cc phn t trong mng kt qu c t thnh <code>null</code>, v nu bn c gng
   1022                 thc hin tham chiu ngc ti mt kt qu cho mt thao tc cha c p dng,
   1023 {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()}
   1024                 s a ra mt li {@link java.lang.Exception}.
   1025 
   1026             </p>
   1027         </dd>
   1028     </dl>
   1029 <p>
   1030     Cc on m HTML sau minh ha cch chn mt lin lc th mi v d liu hng lot. Chng
   1031     bao gm m thit lp mt im kt qu v s dng mt tham chiu li. on m HTML l mt
   1032     phin bn m rng ca phng php <code>createContacEntry()</code>, n l mt phn ca lp
   1033     <code>ContactAdder</code> trong ng dng mu
   1034     <code><a href="{@docRoot}resources/samples/ContactManager/index.html">
   1035     Contact Manager</a></code>.
   1036 </p>
   1037 <p>
   1038     on m HTML u tin truy xut d liu lin lc t UI. Ti im ny, ngi dng 
   1039     chn ti khon m lin lc th mi nn c thm cho ti khon .
   1040 </p>
   1041 <pre>
   1042 // Creates a contact entry from the current UI values, using the currently-selected account.
   1043 protected void createContactEntry() {
   1044     /*
   1045      * Gets values from the UI
   1046      */
   1047     String name = mContactNameEditText.getText().toString();
   1048     String phone = mContactPhoneEditText.getText().toString();
   1049     String email = mContactEmailEditText.getText().toString();
   1050 
   1051     int phoneType = mContactPhoneTypes.get(
   1052             mContactPhoneTypeSpinner.getSelectedItemPosition());
   1053 
   1054     int emailType = mContactEmailTypes.get(
   1055             mContactEmailTypeSpinner.getSelectedItemPosition());
   1056 </pre>
   1057 <p>
   1058     on m HTML tip theo to mt thao tc  chn hng lin lc th vo bng
   1059     {@link android.provider.ContactsContract.RawContacts}:
   1060 </p>
   1061 <pre>
   1062     /*
   1063      * Prepares the batch operation for inserting a new raw contact and its data. Even if
   1064      * the Contacts Provider does not have any data for this person, you can't add a Contact,
   1065      * only a raw contact. The Contacts Provider will then add a Contact automatically.
   1066      */
   1067 
   1068      // Creates a new array of ContentProviderOperation objects.
   1069     ArrayList&lt;ContentProviderOperation&gt; ops =
   1070             new ArrayList&lt;ContentProviderOperation&gt;();
   1071 
   1072     /*
   1073      * Creates a new raw contact with its account type (server type) and account name
   1074      * (user's account). Remember that the display name is not stored in this row, but in a
   1075      * StructuredName data row. No other data is required.
   1076      */
   1077     ContentProviderOperation.Builder op =
   1078             ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
   1079             .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType())
   1080             .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName());
   1081 
   1082     // Builds the operation and adds it to the array of operations
   1083     ops.add(op.build());
   1084 </pre>
   1085 <p>
   1086     Tip theo, m to cc hng d liu cho hng tn hin th, in thoi v e-mail.
   1087 </p>
   1088 <p>
   1089     Tng i tng b dng thao tc s s dng
   1090     {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()}
   1091      nhn
   1092     {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID}. Tham chiu  s tr
   1093     ngc v i tng {@link android.content.ContentProviderResult} t thao tc u tin,
   1094     l thao tc thm hng lin lc th v tr v gi tr {@code android.provider.BaseColumns#_ID}
   1095     mi ca n. Kt qu l, mi hng d liu c t ng lin kt bi
   1096     {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID}
   1097     ca n vi hng {@link android.provider.ContactsContract.RawContacts} mi m n thuc v.
   1098 </p>
   1099 <p>
   1100     i tng {@link android.content.ContentProviderOperation.Builder} thm hng e-mail s c
   1101     gn c bng {@link android.content.ContentProviderOperation.Builder#withYieldAllowed(boolean)
   1102     withYieldAllowed()}, m iu ny t mt im kt qu:
   1103 </p>
   1104 <pre>
   1105     // Creates the display name for the new raw contact, as a StructuredName data row.
   1106     op =
   1107             ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
   1108             /*
   1109              * withValueBackReference sets the value of the first argument to the value of
   1110              * the ContentProviderResult indexed by the second argument. In this particular
   1111              * call, the raw contact ID column of the StructuredName data row is set to the
   1112              * value of the result returned by the first operation, which is the one that
   1113              * actually adds the raw contact row.
   1114              */
   1115             .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
   1116 
   1117             // Sets the data row's MIME type to StructuredName
   1118             .withValue(ContactsContract.Data.MIMETYPE,
   1119                     ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
   1120 
   1121             // Sets the data row's display name to the name in the UI.
   1122             .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);
   1123 
   1124     // Builds the operation and adds it to the array of operations
   1125     ops.add(op.build());
   1126 
   1127     // Inserts the specified phone number and type as a Phone data row
   1128     op =
   1129             ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
   1130             /*
   1131              * Sets the value of the raw contact id column to the new raw contact ID returned
   1132              * by the first operation in the batch.
   1133              */
   1134             .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
   1135 
   1136             // Sets the data row's MIME type to Phone
   1137             .withValue(ContactsContract.Data.MIMETYPE,
   1138                     ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
   1139 
   1140             // Sets the phone number and type
   1141             .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
   1142             .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType);
   1143 
   1144     // Builds the operation and adds it to the array of operations
   1145     ops.add(op.build());
   1146 
   1147     // Inserts the specified email and type as a Phone data row
   1148     op =
   1149             ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
   1150             /*
   1151              * Sets the value of the raw contact id column to the new raw contact ID returned
   1152              * by the first operation in the batch.
   1153              */
   1154             .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
   1155 
   1156             // Sets the data row's MIME type to Email
   1157             .withValue(ContactsContract.Data.MIMETYPE,
   1158                     ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
   1159 
   1160             // Sets the email address and type
   1161             .withValue(ContactsContract.CommonDataKinds.Email.ADDRESS, email)
   1162             .withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType);
   1163 
   1164     /*
   1165      * Demonstrates a yield point. At the end of this insert, the batch operation's thread
   1166      * will yield priority to other threads. Use after every set of operations that affect a
   1167      * single contact, to avoid degrading performance.
   1168      */
   1169     op.withYieldAllowed(true);
   1170 
   1171     // Builds the operation and adds it to the array of operations
   1172     ops.add(op.build());
   1173 </pre>
   1174 <p>
   1175     on m HTML cui cng hin th lnh gi ti
   1176     {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} m
   1177     chn lin lc th mi v cc hng d liu.
   1178 </p>
   1179 <pre>
   1180     // Ask the Contacts Provider to create a new contact
   1181     Log.d(TAG,"Selected account: " + mSelectedAccount.getName() + " (" +
   1182             mSelectedAccount.getType() + ")");
   1183     Log.d(TAG,"Creating contact: " + name);
   1184 
   1185     /*
   1186      * Applies the array of ContentProviderOperation objects in batch. The results are
   1187      * discarded.
   1188      */
   1189     try {
   1190 
   1191             getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
   1192     } catch (Exception e) {
   1193 
   1194             // Display a warning
   1195             Context ctx = getApplicationContext();
   1196 
   1197             CharSequence txt = getString(R.string.contactCreationFailure);
   1198             int duration = Toast.LENGTH_SHORT;
   1199             Toast toast = Toast.makeText(ctx, txt, duration);
   1200             toast.show();
   1201 
   1202             // Log exception
   1203             Log.e(TAG, "Exception encountered while inserting contact: " + e);
   1204     }
   1205 }
   1206 </pre>
   1207 <p>
   1208     Thao tc hng lot cng cho php bn trin khai <strong>kim sot ng thi lc quan</strong>,
   1209     mt phng php p dng cc giao tc sa i m khng phi kha kho lu gi lin quan.
   1210      s dng phng php ny, bn p dng giao tc  ri kim tra cc sa i khc m
   1211     c th  c thc hin ti cng thi im. Nu bn thy  din ra mt sa i khng nht qun,
   1212     hy quay lui giao tc ca bn v th li.
   1213 </p>
   1214 <p>
   1215     Kim sot ng thi lc quan rt hu ch i vi thit b di ng, khi  mi lc ch c mt ngi dng
   1216     v vic truy cp ng thi vo mt kho lu gi d liu him khi xy ra. V khng s dng kha nn
   1217     khng b lng ph thi gian cho vic thit t kha hay ch cc giao tc khc nh kha ca mnh.
   1218 </p>
   1219 <p>
   1220      s dng kim sot ng thi lc quan trong khi ang cp nht mt hng
   1221     {@link android.provider.ContactsContract.RawContacts} n, hy lm theo cc bc sau:
   1222 </p>
   1223 <ol>
   1224     <li>
   1225         Truy xut ct {@link android.provider.ContactsContract.SyncColumns#VERSION}
   1226         ca lin lc th cng vi d liu khc m bn truy xut.
   1227     </li>
   1228     <li>
   1229         To mt i tng {@link android.content.ContentProviderOperation.Builder} ph hp 
   1230         thi hnh mt rng buc, bng cch s dng phng php
   1231         {@link android.content.ContentProviderOperation#newAssertQuery(Uri)}. i vi URI ni dung,
   1232         s dng {@link android.provider.ContactsContract.RawContacts#CONTENT_URI
   1233         RawContacts.CONTENT_URI}
   1234         vi {@code android.provider.BaseColumns#_ID} ca lin lc th c ni vi n.
   1235     </li>
   1236     <li>
   1237         i vi i tng {@link android.content.ContentProviderOperation.Builder}, hy gi
   1238         {@link android.content.ContentProviderOperation.Builder#withValue(String, Object)
   1239         withValue()}  so snh ct {@link android.provider.ContactsContract.SyncColumns#VERSION}
   1240         vi s phin bn bn va truy xut.
   1241     </li>
   1242     <li>
   1243         i vi cng {@link android.content.ContentProviderOperation.Builder}, hy gi
   1244         {@link android.content.ContentProviderOperation.Builder#withExpectedCount(int)
   1245         withExpectedCount()}  m bo rng ch mt hng c kim tra bng xc nhn ny.
   1246     </li>
   1247     <li>
   1248         Gi {@link android.content.ContentProviderOperation.Builder#build()}  to i tng
   1249         {@link android.content.ContentProviderOperation}, ri thm i tng ny lm
   1250         i tng u tin trong {@link java.util.ArrayList} m bn chuyn cho
   1251         {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()}.
   1252     </li>
   1253     <li>
   1254         p dng giao tc hng lot.
   1255     </li>
   1256 </ol>
   1257 <p>
   1258     Nu hng lin lc th c cp nht bi mt thao tc khc gia thi im bn c hng v
   1259     thi im bn c gng sa i n, "xc nhn" {@link android.content.ContentProviderOperation}
   1260     s tht bi, v ton b lot thao tc s c rt khi. Sau , bn c th chn th li
   1261     lot hoc thc hin mt hnh ng khc.
   1262 </p>
   1263 <p>
   1264     on m HTML sau minh ha cch to mt "xc nhn"
   1265     {@link android.content.ContentProviderOperation} sau khi truy vn mt lin lc th n bng cch s dng
   1266     mt {@link android.content.CursorLoader}:
   1267 </p>
   1268 <pre>
   1269 /*
   1270  * The application uses CursorLoader to query the raw contacts table. The system calls this method
   1271  * when the load is finished.
   1272  */
   1273 public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor cursor) {
   1274 
   1275     // Gets the raw contact's _ID and VERSION values
   1276     mRawContactID = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
   1277     mVersion = cursor.getInt(cursor.getColumnIndex(SyncColumns.VERSION));
   1278 }
   1279 
   1280 ...
   1281 
   1282 // Sets up a Uri for the assert operation
   1283 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, mRawContactID);
   1284 
   1285 // Creates a builder for the assert operation
   1286 ContentProviderOperation.Builder assertOp = ContentProviderOperation.netAssertQuery(rawContactUri);
   1287 
   1288 // Adds the assertions to the assert operation: checks the version and count of rows tested
   1289 assertOp.withValue(SyncColumns.VERSION, mVersion);
   1290 assertOp.withExpectedCount(1);
   1291 
   1292 // Creates an ArrayList to hold the ContentProviderOperation objects
   1293 ArrayList ops = new ArrayList&lt;ContentProviderOperationg&gt;;
   1294 
   1295 ops.add(assertOp.build());
   1296 
   1297 // You would add the rest of your batch operations to "ops" here
   1298 
   1299 ...
   1300 
   1301 // Applies the batch. If the assert fails, an Exception is thrown
   1302 try
   1303     {
   1304         ContentProviderResult[] results =
   1305                 getContentResolver().applyBatch(AUTHORITY, ops);
   1306 
   1307     } catch (OperationApplicationException e) {
   1308 
   1309         // Actions you want to take if the assert operation fails go here
   1310     }
   1311 </pre>
   1312 <h3 id="Intents">Truy xut v sa i bng  nh</h3>
   1313 <p>
   1314     Vic gi mt  nh ti ng dng danh b ca thit b cho php bn truy cp Trnh cung cp Danh b
   1315     mt cch gin tip.  nh s khi ng UI ng dng danh b ca thit b, trong  ngi dng c th
   1316     thc hin cng vic lin quan ti danh b. Vi kiu truy cp ny, ngi dng c th:
   1317     <ul>
   1318         <li>Chn mt lin lc t danh sch v tr n v ng dng ca bn  lm vic tip.</li>
   1319         <li>Chnh sa d liu ca mt lin lc hin c.</li>
   1320         <li>Chn mt lin lc th mi cho bt k ti khon no ca h.</li>
   1321         <li>Xa mt lin lc hoc d liu danh b.</li>
   1322     </ul>
   1323 <p>
   1324     Nu ngi dng ang chn hoc cp nht d liu, bn c th thu thp d liu trc v gi n nh
   1325     mt phn ca  nh.
   1326 </p>
   1327 <p>
   1328     Khi bn s dng  nh  truy cp Trnh cung cp Danh b thng qua ng dng danh b ca thit b, bn
   1329     khng phi ghi UI hay m ca chnh mnh  truy nhp trnh cung cp. Bn cng khng phi
   1330     yu cu quyn c hoc ghi n trnh cung cp. ng dng danh b ca thit b c th
   1331     cp quyn c i vi mt lin lc cho bn, v v bn ang thc hin sa i i vi
   1332     trnh cung cp thng qua mt ng dng khc, bn khng cn phi c quyn ghi.
   1333 </p>
   1334 <p>
   1335     Tin trnh chung  gi mt  nh nhm truy cp mt trnh cung cp c m t chi tit trong hng dn
   1336     <a href="{@docRoot}guide/topics/providers/content-provider-basics.html">
   1337     Ni dung C bn v Trnh cung cp Ni dung</a> trong phn "Truy cp d liu thng qua  nh." Hnh ng,
   1338     kiu MIME, v cc gi tr d liu bn s dng cho cc tc v c sn c tm tt trong Bng 4, trong khi cc gi tr
   1339     ph thm m bn c th s dng vi
   1340     {@link android.content.Intent#putExtra(String, String) putExtra()} c lit k trong
   1341     ti liu tham kho cho {@link android.provider.ContactsContract.Intents.Insert}:
   1342 </p>
   1343 <p class="table-caption" id="table4">
   1344   <strong>Bng 4.</strong>  nh ca Trnh cung cp Danh b.
   1345 </p>
   1346 <table style="width:75%">
   1347     <tr>
   1348         <th scope="col" style="width:10%">Tc v</th>
   1349         <th scope="col" style="width:5%">Hnh ng</th>
   1350         <th scope="col" style="width:10%">D liu</th>
   1351         <th scope="col" style="width:10%">Kiu MIME</th>
   1352         <th scope="col" style="width:25%">Lu </th>
   1353     </tr>
   1354     <tr>
   1355         <td><strong>Chn mt lin lc t danh sch</strong></td>
   1356         <td>{@link android.content.Intent#ACTION_PICK}</td>
   1357         <td>
   1358             Mt trong:
   1359             <ul>
   1360                 <li>
   1361 {@link android.provider.ContactsContract.Contacts#CONTENT_URI Contacts.CONTENT_URI},
   1362                     m hin th mt danh sch cc lin lc.
   1363                 </li>
   1364                 <li>
   1365 {@link android.provider.ContactsContract.CommonDataKinds.Phone#CONTENT_URI Phone.CONTENT_URI},
   1366                     m hin th mt danh sch cc s in thoi cho mt lin lc th.
   1367                 </li>
   1368                 <li>
   1369 {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#CONTENT_URI
   1370 StructuredPostal.CONTENT_URI},
   1371                     m hin th mt danh sch cc a ch bu in cho mt lin lc th.
   1372                 </li>
   1373                 <li>
   1374 {@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_URI Email.CONTENT_URI},
   1375                     m hin th mt danh sch cc a ch e-mail cho mt lin lc th.
   1376                 </li>
   1377             </ul>
   1378         </td>
   1379         <td>
   1380             Khng s dng
   1381         </td>
   1382         <td>
   1383             Hin th mt danh sch cc lin lc th hoc danh sch d liu t mt lin lc th, ty vo kiu
   1384             URI ni dung m bn cung cp.
   1385             <p>
   1386                 Gi
   1387          {@link android.app.Activity#startActivityForResult(Intent, int) startActivityForResult()},
   1388                 n tr v URI ni dung ca hng c chn. Hnh thc ca URI l URI ni dung
   1389                 ca bng vi <code>LOOKUP_ID</code> ca hng c ni vi n.
   1390                 ng dng danh b ca thit b cp quyn c v ghi cho URI ni dung ny
   1391                 trong sut thi gian hot ng ca bn. Xem hng dn
   1392                 <a href="{@docRoot}guide/topics/providers/content-provider-basics.html">
   1393                 Ni dung C bn v Trnh cung cp Ni dung</a>  bit thm chi tit.
   1394             </p>
   1395         </td>
   1396     </tr>
   1397     <tr>
   1398         <td><strong>Chn mt lin lc th mi</strong></td>
   1399         <td>{@link android.provider.ContactsContract.Intents.Insert#ACTION Insert.ACTION}</td>
   1400         <td>Khng p dng</td>
   1401         <td>
   1402             {@link android.provider.ContactsContract.RawContacts#CONTENT_TYPE
   1403             RawContacts.CONTENT_TYPE}, kiu MIME cho mt tp hp lin cc lc th.
   1404         </td>
   1405         <td>
   1406             Hin th mn hnh <strong>Thm Lin lc</strong> ca ng dng danh b ca thit b. Cc
   1407             gi tr ph thm m bn thm vo  nh s c hin th. Nu c gi bng
   1408         {@link android.app.Activity#startActivityForResult(Intent, int) startActivityForResult()},
   1409             URI ni dung ca lin lc th mi thm s c chuyn li cho phng php gi li
   1410             {@link android.app.Activity#onActivityResult(int, int, Intent) onActivityResult()}
   1411             ca hot ng ca bn trong tham i {@link android.content.Intent}, trong
   1412             trng "d liu".  nhn gi tr, hy gi {@link android.content.Intent#getData()}.
   1413         </td>
   1414     </tr>
   1415     <tr>
   1416         <td><strong>Chnh sa mt lin lc</strong></td>
   1417         <td>{@link android.content.Intent#ACTION_EDIT}</td>
   1418         <td>
   1419             {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} i vi
   1420             lin lc. Hot ng ca trnh chnh sa s cho php ngi dng chnh sa bt k d liu no c lin kt
   1421             vi lin lc ny.
   1422         </td>
   1423         <td>
   1424             {@link android.provider.ContactsContract.Contacts#CONTENT_ITEM_TYPE
   1425             Contacts.CONTENT_ITEM_TYPE}, mt lin lc n.</td>
   1426         <td>
   1427             Hin th mn hnh Chnh sa Lin lc trong ng dng danh b. Cc gi tr ph thm m bn thm
   1428             vo  nh s c hin th. Khi ngi dng nhp vo <strong>Xong</strong>  lu cc
   1429             chnh sa, hot ng ca bn quay li tin cnh.
   1430         </td>
   1431     </tr>
   1432     <tr>
   1433         <td><strong>Hin th mt trnh chn m cng c th thm d liu.</strong></td>
   1434         <td>{@link android.content.Intent#ACTION_INSERT_OR_EDIT}</td>
   1435         <td>
   1436             Khng p dng
   1437         </td>
   1438         <td>
   1439             {@link android.provider.ContactsContract.Contacts#CONTENT_ITEM_TYPE}
   1440         </td>
   1441          <td>
   1442              nh ny lun hin th mn hnh b chn ca ng dng danh b. Ngi dng c th hoc
   1443             chn mt lin lc  chnh sa, hoc thm mt lin lc mi. Hoc mn hnh chnh sa hoc mn hnh thm
   1444             s xut hin, ty vo la chn ca ngi dng, v d liu ph thm m bn chuyn trong  nh
   1445            s c hin th. Nu ng dng ca bn hin th d liu chng hn nh e-mail hoc s in thoi, hy s dng
   1446              nh ny  cho php ngi dng thm d liu vo mt lin lc hin ti.
   1447             lin lc,
   1448             <p class="note">
   1449                 <strong>Lu :</strong> Khng cn gi mt gi tr tn trong phn ph thm ca  nh,
   1450                 v ngi dng lun chn mt tn hin c hoc thm mt tn mi. Thm na,
   1451                 nu bn gi mt tn, v ngi dng chn thc hin chnh sa, ng dng danh b s
   1452                 hin th tn m bn gi, ghi  gi tr trc. Nu ngi dng khng
   1453                   thy iu ny v lu chnh sa, gi tr c s b mt.
   1454             </p>
   1455          </td>
   1456     </tr>
   1457 </table>
   1458 <p>
   1459     ng dng danh b ca thit b khng cho php bn xa mt lin lc th hay bt k d liu no bng mt
   1460      nh. Thay vo ,  xa mt lin lc th, hy s dng
   1461     {@link android.content.ContentResolver#delete(Uri, String, String[]) ContentResolver.delete()}
   1462     hoc {@link android.content.ContentProviderOperation#newDelete(Uri)
   1463     ContentProviderOperation.newDelete()}.
   1464 </p>
   1465 <p>
   1466     on m HTML sau minh ha cch xy dng v gi mt  nh  chn mt lin lc th mi v
   1467     d liu:
   1468 </p>
   1469 <pre>
   1470 // Gets values from the UI
   1471 String name = mContactNameEditText.getText().toString();
   1472 String phone = mContactPhoneEditText.getText().toString();
   1473 String email = mContactEmailEditText.getText().toString();
   1474 
   1475 String company = mCompanyName.getText().toString();
   1476 String jobtitle = mJobTitle.getText().toString();
   1477 
   1478 // Creates a new intent for sending to the device's contacts application
   1479 Intent insertIntent = new Intent(ContactsContract.Intents.Insert.ACTION);
   1480 
   1481 // Sets the MIME type to the one expected by the insertion activity
   1482 insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
   1483 
   1484 // Sets the new contact name
   1485 insertIntent.putExtra(ContactsContract.Intents.Insert.NAME, name);
   1486 
   1487 // Sets the new company and job title
   1488 insertIntent.putExtra(ContactsContract.Intents.Insert.COMPANY, company);
   1489 insertIntent.putExtra(ContactsContract.Intents.Insert.JOB_TITLE, jobtitle);
   1490 
   1491 /*
   1492  * Demonstrates adding data rows as an array list associated with the DATA key
   1493  */
   1494 
   1495 // Defines an array list to contain the ContentValues objects for each row
   1496 ArrayList&lt;ContentValues&gt; contactData = new ArrayList&lt;ContentValues&gt;();
   1497 
   1498 
   1499 /*
   1500  * Defines the raw contact row
   1501  */
   1502 
   1503 // Sets up the row as a ContentValues object
   1504 ContentValues rawContactRow = new ContentValues();
   1505 
   1506 // Adds the account type and name to the row
   1507 rawContactRow.put(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType());
   1508 rawContactRow.put(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName());
   1509 
   1510 // Adds the row to the array
   1511 contactData.add(rawContactRow);
   1512 
   1513 /*
   1514  * Sets up the phone number data row
   1515  */
   1516 
   1517 // Sets up the row as a ContentValues object
   1518 ContentValues phoneRow = new ContentValues();
   1519 
   1520 // Specifies the MIME type for this data row (all data rows must be marked by their type)
   1521 phoneRow.put(
   1522         ContactsContract.Data.MIMETYPE,
   1523         ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
   1524 );
   1525 
   1526 // Adds the phone number and its type to the row
   1527 phoneRow.put(ContactsContract.CommonDataKinds.Phone.NUMBER, phone);
   1528 
   1529 // Adds the row to the array
   1530 contactData.add(phoneRow);
   1531 
   1532 /*
   1533  * Sets up the email data row
   1534  */
   1535 
   1536 // Sets up the row as a ContentValues object
   1537 ContentValues emailRow = new ContentValues();
   1538 
   1539 // Specifies the MIME type for this data row (all data rows must be marked by their type)
   1540 emailRow.put(
   1541         ContactsContract.Data.MIMETYPE,
   1542         ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE
   1543 );
   1544 
   1545 // Adds the email address and its type to the row
   1546 emailRow.put(ContactsContract.CommonDataKinds.Email.ADDRESS, email);
   1547 
   1548 // Adds the row to the array
   1549 contactData.add(emailRow);
   1550 
   1551 /*
   1552  * Adds the array to the intent's extras. It must be a parcelable object in order to
   1553  * travel between processes. The device's contacts app expects its key to be
   1554  * Intents.Insert.DATA
   1555  */
   1556 insertIntent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, contactData);
   1557 
   1558 // Send out the intent to start the device's contacts app in its add contact activity.
   1559 startActivity(insertIntent);
   1560 </pre>
   1561 <h3 id="DataIntegrity">Ton vn d liu</h3>
   1562 <p>
   1563     V kho lu gi danh b cha d liu quan trng v nhy cm m ngi dng cho l
   1564     ng v cp nht, Trnh cung cp Danh b c cc quy tc v ton vn d liu c nh ngha r rng. Bn c
   1565     trch nhim tun theo nhng quy tc ny khi sa i d liu danh b. Cc quy tc
   1566     quan trng c lit k  y:
   1567 </p>
   1568 <dl>
   1569     <dt>
   1570         Lun thm mt hng {@link android.provider.ContactsContract.CommonDataKinds.StructuredName} cho
   1571         mi hng {@link android.provider.ContactsContract.RawContacts} m bn thm.
   1572     </dt>
   1573     <dd>
   1574         Hng {@link android.provider.ContactsContract.RawContacts} khng c mt hng
   1575         {@link android.provider.ContactsContract.CommonDataKinds.StructuredName} trong bng
   1576         {@link android.provider.ContactsContract.Data} c th gy ra s c trong khi
   1577         tng hp.
   1578     </dd>
   1579     <dt>
   1580         Lun lin kt cc hng {@link android.provider.ContactsContract.Data} mi vi hng
   1581         {@link android.provider.ContactsContract.RawContacts} m ca chng.
   1582     </dt>
   1583     <dd>
   1584         Mi hng {@link android.provider.ContactsContract.Data} m khng c lin kt vi mt
   1585         {@link android.provider.ContactsContract.RawContacts} s khng hin th trong ng dng danh b
   1586          ca thit b, v n c th gy ra s c vi trnh iu hp ng b.
   1587     </dd>
   1588     <dt>
   1589         Ch thay i d liu i vi nhng lin lc th m bn s hu.
   1590     </dt>
   1591     <dd>
   1592         Nh rng Trnh cung cp Danh b lun qun l d liu t vi
   1593         loi ti khon/dch v trc tuyn khc nhau. Bn cn m bo rng ng dng ca bn ch sa i
   1594         hoc xa d liu i vi cc hng thuc v bn, v rng n ch chn d liu c
   1595         loi v tn ti khon m bn kim sot.
   1596     </dd>
   1597     <dt>
   1598         Lun s dng cc hng s c nh ngha trong {@link android.provider.ContactsContract} v cc lp con ca n
   1599         i vi thm quyn, URI ni dung, ng dn URI, tn ct, kiu MIME, v cc gi tr
   1600         {@link android.provider.ContactsContract.CommonDataKinds.CommonColumns#TYPE}.
   1601     </dt>
   1602     <dd>
   1603         S dng nhng hng s ny s gip bn trnh gp li. Bn cng s c thng bo bng cnh bo
   1604         t trnh bin dch nu bt k hng s no khng c chp nhn.
   1605     </dd>
   1606 </dl>
   1607 <h3 id="CustomData">Hng d liu ty chnh</h3>
   1608 <p>
   1609     Bng cch to v s dng cc kiu MIME ty chnh ca chnh mnh, bn c th chn, chnh sa, xa v truy xut
   1610     cc hng d liu ca chnh mnh trong bng {@link android.provider.ContactsContract.Data}. Cc hng ca bn
   1611     b gii hn bng cch s dng ct c nh ngha trong
   1612     {@link android.provider.ContactsContract.DataColumns}, mc d bn c th nh x
   1613     tn ct theo kiu ca chnh mnh vi tn ct mc nh. Trong ng dng danh b ca thit b,
   1614     d liu cho cc hng ca bn c hin th nhng khng th chnh sa hay xa c, v ngi dng khng th thm
   1615     d liu b sung.  cho php ngi dng sa i cc hng d liu ty chnh ca mnh, bn phi cung cp mt hot ng
   1616     trnh chnh sa trong ng dng ca chnh mnh.
   1617 </p>
   1618 <p>
   1619      hin th d liu ty chnh ca mnh, hy cung cp mt tp <code>contacts.xml</code> cha mt phn t
   1620     <code>&lt;ContactsAccountType&gt;</code> v mt hoc nhiu phn t con
   1621     <code>&lt;ContactsDataKind&gt;</code> ca n. iu ny c m t chi tit hn trong
   1622     phn <a href="#SocialStreamDataKind"><code>&lt;ContactsDataKind&gt; element</code></a>.
   1623 </p>
   1624 <p>
   1625      tm hiu thm v cc kiu MIME ty chnh, hy c hng dn
   1626     <a href="{@docRoot}guide/topics/providers/content-provider-creating.html">
   1627     To mt Trnh cung cp Ni dung</a>.
   1628 </p>
   1629 <h2 id="SyncAdapters">Trnh iu hp ng b Trnh cung cp Danh b</h2>
   1630 <p>
   1631     Trnh cung cp Danh b c thit k ring  x l <strong>ng b ho</strong>
   1632     d liu danh b gia mt thit b v mt dch v trc tuyn. iu ny cho php ngi dng ti
   1633     d liu hin c xung mt thit b mi v ti d liu hin c ln mt ti khon mi.
   1634     ng b ho cng m bo rng ngi dng c sn d liu mi nht, khng ph thuc vo
   1635     ngun ca cc b sung v thay i. Mt u im khc ca ng b ho  l n khin
   1636     d liu danh b c sn ngay c khi thit b khng c kt ni vi mng.
   1637 </p>
   1638 <p>
   1639     Mc d bn c th trin khai ng b ho theo nhiu cch, h thng Android cung cp
   1640     mt khun kh ng b ha b tr c kh nng t ng ha nhng tc v sau:
   1641     <ul>
   1642 
   1643     <li>
   1644         Kim tra s sn sng ca mng.
   1645     </li>
   1646     <li>
   1647         Lp lch biu v thc hin ng b ho da trn ty chn ca ngi dng.
   1648     </li>
   1649     <li>
   1650         Khi ng li nhng ng b ho  dng.
   1651     </li>
   1652     </ul>
   1653 <p>
   1654      s dng khun kh ny, bn phi cung cp mt phn b tr trnh iu hp ng b. Mi trnh iu hp ng b l duy nht i vi
   1655     mt dch v v trnh cung cp ni dung, nhng c th x l nhiu tn ti khon cho cng dch v. Khun kh
   1656     cng cho php nhiu trnh iu hp ng b cho cng dch v v trnh cung cp.
   1657 </p>
   1658 <h3 id="SyncClassesFiles">Cc lp v tp trnh iu hp ng b</h3>
   1659 <p>
   1660     Bn trin khai mt trnh iu hp ng b lm lp con ca
   1661     {@link android.content.AbstractThreadedSyncAdapter} v ci t n nh mt phn ca mt ng dng
   1662     Android. H thng bit v trnh iu hp ng b t cc phn t trong bn k khai ng dng
   1663     ca n, v t mt tp XML c bit c ch n trong bn k khai. Tp XML s nh ngha
   1664     loi ti khon cho dch v trc tuyn v thm quyn cho trnh cung cp ni dung, cng nhau chng
   1665    xc nh duy nht mt trnh iu hp. Trnh iu hp ng b khng c kch hot cho ti khi ngi dng thm mt
   1666     ti khon cho loi ti khon ca trnh iu hp ng b v kch hot ng b ho cho trnh cung cp
   1667     ni dung m trnh iu hp ng b s ng b cng.  Ti thi im , h thng bt u qun l trnh iu hp,
   1668     gi n nu cn thit  ng b ho gia trnh cung cp ni dung v my ch.
   1669 </p>
   1670 <p class="note">
   1671     <strong>Lu :</strong> Vic s dng mt loi ti khon  tham gia nhn bit trnh iu hp ng b s cho php
   1672     h thng pht hin v nhm cng nhau nhng trnh iu hp ng b truy cp cc dch v khc nhau t
   1673     cng t chc. V d, cc trnh iu hp ng b cho dch v trc tuyn ca Google u c cng
   1674     loi ti khon <code>com.google</code>. Khi ngi dng thm mt ti khon Google vo thit b ca mnh, tt c
   1675     trnh iu hp ng b c ci t cho dch v Google c lit k cng nhau; mi trnh iu hp ng b
   1676     c lit k s ng b vi mt trnh cung cp ni dung khc nhau trn thit b.
   1677 </p>
   1678 <p>
   1679     V hu ht dch v u yu cu ngi dng xc minh danh tnh ca h trc khi truy cp
   1680     d liu, h thng Android cung cp mt khun kh xc thc tng t nh v thng
   1681     c s dng cng vi khun kh ca trnh iu hp ng b. Khun kh xc thc s dng
   1682     cc trnh xc thc b tr l lp con ca
   1683     {@link android.accounts.AbstractAccountAuthenticator}. Mt trnh xc thc s xc minh
   1684     danh tnh ca ngi dng theo cc bc sau:
   1685     <ol>
   1686         <li>
   1687             Thu thp tn, mt khu hoc thng tin tng t ca ngi dng (
   1688 <strong>thng tin xc thc</strong> ca ngi dng).
   1689         </li>
   1690         <li>
   1691             Gi thng tin xc thc ti dch v
   1692         </li>
   1693         <li>
   1694             Kim tra tr li ca dch v.
   1695         </li>
   1696     </ol>
   1697 <p>
   1698     Nu dch v chp nhn thng tin xc thc, trnh xc thc c th
   1699     lu gi thng tin xc thc   s dng sau. V khun kh trnh xc thc b tr,
   1700     {@link android.accounts.AccountManager} c th cung cp quyn truy cp bt k token xc thc no m mt trnh xc thc
   1701     h tr v chn hin ra, chng hn nh token xc thc OAuth2.
   1702 </p>
   1703 <p>
   1704     Mc d khng yu cu xc thc, phn ln dch v danh b u s dng n.
   1705     Tuy nhin, bn khng phi s dng khun kh xc thc ca Android  thc hin xc thc.
   1706 </p>
   1707 <h3 id="SyncAdapterImplementing">Trin khai trnh iu hp ng b</h3>
   1708 <p>
   1709      trin khai mt trnh iu hp ng b cho Trnh cung cp Danh b, bn bt u bng cch to mt
   1710     ng dng Android cha:
   1711 </p>
   1712     <dl>
   1713         <dt>
   1714             Mt thnh phn {@link android.app.Service}  hi p li cc yu cu t h thng nhm
   1715             gn kt vi trnh iu hp ng b.
   1716         </dt>
   1717         <dd>
   1718             Khi h thng mun chy ng b ho, n gi phng php
   1719             {@link android.app.Service#onBind(Intent) onBind()} ca dch v v nhn mt
   1720             {@link android.os.IBinder} cho trnh iu hp ng b. iu ny cho php h thng thc hin
   1721             lnh gi lin tin trnh ti cc phng php ca trnh iu hp.
   1722             <p>
   1723                 Trong ng dng mu<a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">
   1724                 Trnh iu hp ng b Mu</a>, tn lp ca dch v ny l
   1725                 <code>com.example.android.samplesync.syncadapter.SyncService</code>.
   1726             </p>
   1727         </dd>
   1728         <dt>
   1729             Trnh iu hp ng b thc t, c trin khai nh mt lp con c th ca
   1730             {@link android.content.AbstractThreadedSyncAdapter}.
   1731         </dt>
   1732         <dd>
   1733             Lp ny thc hin cng vic ti xung d liu t my ch, ti ln d liu t
   1734             thit b, v x l xung t. Cng vic chnh ca trnh iu hp c
   1735             thc hin trong phng php {@link android.content.AbstractThreadedSyncAdapter#onPerformSync(
   1736             Account, Bundle, String, ContentProviderClient, SyncResult)
   1737             onPerformSync()}. Lp ny phi c khi to nh mt i tng duy nht (singleton).
   1738             <p>
   1739                 Trong ng dng mu <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">
   1740                 Trnh iu hp ng b Mu</a>, trnh iu hp ng b c nh ngha trong lp
   1741                 <code>com.example.android.samplesync.syncadapter.SyncAdapter</code>.
   1742             </p>
   1743         </dd>
   1744         <dt>
   1745             Mt lp con ca {@link android.app.Application}.
   1746         </dt>
   1747         <dd>
   1748             Lp ny ng vai tr nh mt nh my cho i tng duy nht ca trnh iu hp ng b. S dng phng php
   1749             {@link android.app.Application#onCreate()}  khi to trnh iu hp ng b, v
   1750             cung cp mt phng php "b nhn" tnh  tr i tng duy nht v phng php
   1751             {@link android.app.Service#onBind(Intent) onBind()} ca dch v
   1752             ca trnh iu hp ng b.
   1753         </dd>
   1754         <dt>
   1755             <strong>Ty chn:</strong> Mt thnh phn {@link android.app.Service}  hi p li
   1756             cc yu cu t h thng v xc thc ngi dng.
   1757         </dt>
   1758         <dd>
   1759             {@link android.accounts.AccountManager} khi ng dch v ny  bt u tin trnh
   1760             xc thc. Phng php {@link android.app.Service#onCreate()} ca dch v ny s khi to mt
   1761             i tng trnh xc thc. Khi h thng mun xc thc mt ti khon ngi dng cho trnh iu hp ng b
   1762             ca ng dng, n s gi phng php
   1763             {@link android.app.Service#onBind(Intent) onBind()} ca dch v  nhn mt
   1764             {@link android.os.IBinder} cho trnh xc thc. iu ny cho php h thng thc hin
   1765             lnh gi lin tin trnh ti cc phng php ca trnh xc thc.
   1766             <p>
   1767                 Trong ng dng mu<a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">
   1768                 Trnh iu hp ng b Mu</a>, tn lp ca dch v ny l
   1769                 <code>com.example.android.samplesync.authenticator.AuthenticationService</code>.
   1770             </p>
   1771         </dd>
   1772         <dt>
   1773             <strong>Ty chn:</strong> Mt lp con c th ca
   1774             {@link android.accounts.AbstractAccountAuthenticator}  x l cc yu cu v
   1775             xc thc.
   1776         </dt>
   1777         <dd>
   1778             Lp ny cung cp cc phng php m {@link android.accounts.AccountManager} gi ra
   1779              xc thc cc thng tin xc thc ca ngi dng vi my ch. Cc chi tit ca
   1780             tin trnh xc thc rt khc nhau da trn cng ngh my ch ang s dng. Bn nn
   1781             tham kho ti liu cho phn mm my ch ca mnh  tm hiu thm v xc thc.
   1782             <p>
   1783                 Trong ng dng mu <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">
   1784                 Trnh iu hp ng b Mu</a>, trnh xc thc c nh ngha trong lp
   1785                 <code>com.example.android.samplesync.authenticator.Authenticator</code>.
   1786             </p>
   1787         </dd>
   1788         <dt>
   1789             Cc tp XML  nh ngha trnh iu hp ng b v trnh xc thc cho h thng.
   1790         </dt>
   1791         <dd>
   1792             Cc thnh phn dch v trnh iu hp ng b v trnh xc thc  nu c
   1793             nh ngha trong cc phn t
   1794 <code>&lt;<a href="{@docRoot}guide/topics/manifest/service-element.html">service</a>&gt;</code>
   1795              bn k khai ca ng dng. Nhng phn t ny
   1796             cha cc phn t con
   1797 <code>&lt;<a href="{@docRoot}guide/topics/manifest/meta-data-element.html">meta-data</a>&gt;</code>
   1798 m cung cp d liu c th cho
   1799             h thng:
   1800             <ul>
   1801                 <li>
   1802                     Phn t
   1803 <code>&lt;<a href="{@docRoot}guide/topics/manifest/meta-data-element.html">meta-data</a>&gt;</code>
   1804                     cho dch v trnh iu hp ng b s tr v
   1805                     tp XML <code>res/xml/syncadapter.xml</code>. n lt mnh, tp ny quy nh
   1806                     mt URI cho dch v web m s c ng b ha vi Trnh cung cp Danh b,
   1807                     v mt loi ti khon cho dch v web.
   1808                 </li>
   1809                 <li>
   1810                     <strong>Ty chn:</strong> Phn t
   1811 <code>&lt;<a href="{@docRoot}guide/topics/manifest/meta-data-element.html">meta-data</a>&gt;</code>
   1812                     cho trnh xc thc s tr v tp XML
   1813                     <code>res/xml/authenticator.xml</code>. n lt mnh, tp ny quy nh
   1814                     loi ti khon m trnh xc thc ny h tr, cng nh cc ti nguyn UI m
   1815                     xut hin trong tin trnh xc thc. Loi ti khon c quy nh trong phn t
   1816                     ny phi ging nh loi ti khon c quy nh cho trnh iu hp
   1817                     ng b.
   1818                 </li>
   1819             </ul>
   1820         </dd>
   1821     </dl>
   1822 <h2 id="SocialStream">D liu t Lung X hi</h2>
   1823 <p>
   1824     Cc bng {@code android.provider.ContactsContract.StreamItems} v
   1825     {@code android.provider.ContactsContract.StreamItemPhotos} qun l
   1826     d liu n t cc mng x hi. Bn c th ghi mt trnh iu hp ng b m thm d liu lung t
   1827     mng ca chnh mnh vo nhng bng ny, hoc bn c th c d liu lung t nhng bng ny v
   1828     hin th n trong ng dng ca chnh mnh, hoc c hai. Vi nhng tnh nng ny, cc dch v v ng dng
   1829     mng x hi ca bn c th c tch hp vo tri nghim mng x hi ca Android.
   1830 </p>
   1831 <h3 id="StreamText">Vn bn t lung x hi</h3>
   1832 <p>
   1833     Cc mc dng d liu lun c lin kt vi mt lin lc th.
   1834     {@code android.provider.ContactsContract.StreamItemsColumns#RAW_CONTACT_ID} lin kt vi gi tr
   1835     <code>_ID</code> ca lin lc th mi. Loi ti khon v tn ti khon ca lin lc th
   1836     cng c lu gi trong hng mc dng.
   1837 </p>
   1838 <p>
   1839     Lu gi d liu t lung ca bn vo nhng ct sau:
   1840 </p>
   1841 <dl>
   1842     <dt>
   1843         {@code android.provider.ContactsContract.StreamItemsColumns#ACCOUNT_TYPE}
   1844     </dt>
   1845     <dd>
   1846         <strong>Bt buc.</strong> Loi ti khon ca ngi dng i vi lin lc th c lin kt vi mc dng
   1847         ny. Nh t gi tr ny khi bn chn mt mc dng.
   1848     </dd>
   1849     <dt>
   1850         {@code android.provider.ContactsContract.StreamItemsColumns#ACCOUNT_NAME}
   1851     </dt>
   1852     <dd>
   1853         <strong>Bt buc.</strong> Tn ti khon ca ngi dng i vi lin lc th c lin kt vi mc dng
   1854         ny. Nh t gi tr ny khi bn chn mt mc dng.
   1855     </dd>
   1856     <dt>
   1857         Ct m nh danh
   1858     </dt>
   1859     <dd>
   1860         <strong>Bt buc.</strong> Bn phi chn cc ct m nh danh sau khi chn
   1861         mt mc dng:
   1862         <ul>
   1863             <li>
   1864                 {@code android.provider.ContactsContract.StreamItemsColumns#CONTACT_ID}: Gi tr
   1865                 {@code android.provider.BaseColumns#_ID} ca lin lc m mc dng
   1866                 ny c lin kt vi.
   1867             </li>
   1868             <li>
   1869                 {@code android.provider.ContactsContract.StreamItemsColumns#CONTACT_LOOKUP_KEY}: Gi tr
   1870                 {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} ca lin lc
   1871                 m mc dng ny c lin kt vi.
   1872             </li>
   1873             <li>
   1874                 {@code android.provider.ContactsContract.StreamItemsColumns#RAW_CONTACT_ID}: Gi tr
   1875                 {@code android.provider.BaseColumns#_ID} ca lin lc th m mc dng ny
   1876                 c lin kt vi.
   1877             </li>
   1878         </ul>
   1879     </dd>
   1880     <dt>
   1881         {@code android.provider.ContactsContract.StreamItemsColumns#COMMENTS}
   1882     </dt>
   1883     <dd>
   1884         Ty chn. Lu gi thng tin tm tt m bn c th hin th  phn u ca mt mc dng.
   1885     </dd>
   1886     <dt>
   1887         {@code android.provider.ContactsContract.StreamItemsColumns#TEXT}
   1888     </dt>
   1889     <dd>
   1890         Vn bn ca mc dng, hoc l ni dung  c ng bi ngun ca mc ,
   1891         hoc l m t v mt s hnh ng  khi to mc dng. Ct ny c th cha
   1892         bt k hnh nh ti nguyn nh dng v c nhng no m c th c kt xut bi
   1893         {@link android.text.Html#fromHtml(String) fromHtml()}. Trnh cung cp c th ct bt hoc
   1894         ct ngn bng du ba chm cc ni dung di, nhng s c gng trnh lm hng cc tag.
   1895     </dd>
   1896     <dt>
   1897         {@code android.provider.ContactsContract.StreamItemsColumns#TIMESTAMP}
   1898     </dt>
   1899     <dd>
   1900         Xu vn bn cha thi gian m mc dng c chn hoc cp nht, c
   1901         dng <em>mili giy</em> tri qua k t gi epoch. Nhng ng dng chn hoc cp nht mc dng s chu
   1902         trch nhim  duy tr ct ny; n khng c t ng duy tr bi
   1903         Trnh cung cp Danh b.
   1904     </dd>
   1905 </dl>
   1906 <p>
   1907      hin th thng tin nhn dng cho cc mc dng ca bn, hy s dng
   1908     {@code android.provider.ContactsContract.StreamItemsColumns#RES_ICON},
   1909     {@code android.provider.ContactsContract.StreamItemsColumns#RES_LABEL}, v
   1910     {@code android.provider.ContactsContract.StreamItemsColumns#RES_PACKAGE}  lin kt vi cc ti nguyn
   1911     trong ng dng ca mnh.
   1912 </p>
   1913 <p>
   1914     Bng {@code android.provider.ContactsContract.StreamItems} cha cc ct
   1915     {@code android.provider.ContactsContract.StreamItemsColumns#SYNC1} thng qua
   1916     {@code android.provider.ContactsContract.StreamItemsColumns#SYNC4} dnh ring  s dng
   1917     trnh iu hp ng b.
   1918 </p>
   1919 <h3 id="StreamPhotos">nh t lung x hi</h3>
   1920 <p>
   1921    Bng {@code android.provider.ContactsContract.StreamItemPhotos} lu gi nh c lin kt
   1922    vi mt mc dng. Ct
   1923    {@code android.provider.ContactsContract.StreamItemPhotosColumns#STREAM_ITEM_ID} ca bng
   1924    lin kt vi cc gi tr trong {@code android.provider.BaseColumns#_ID} ca bng
   1925    {@code android.provider.ContactsContract.StreamItems}. Cc tham chiu nh c lu gi trong
   1926    bng  nhng ct ny:
   1927 </p>
   1928 <dl>
   1929     <dt>
   1930         Ct {@code android.provider.ContactsContract.StreamItemPhotos#PHOTO} (mt BLOB).
   1931     </dt>
   1932     <dd>
   1933         Biu din dng nh phn ca nh, c trnh cung cp i kch c  lu gi v hin th.
   1934         Ct ny c sn  tng thch ngc vi cc phin bn trc ca Trnh cung cp
   1935         Danh b m  s dng n  lu gi nh. Tuy nhin, trong phin bn hin ti
   1936         bn khng nn s dng ct ny  lu gi nh. Thay vo , hy s dng
   1937         hoc {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_FILE_ID} hoc
   1938         {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_URI} (c hai
   1939         u c m t trong cc im sau)  lu gi nh trong mt tp. Lc ny, ct ny
   1940         cha mt hnh thu nh ca nh sn sng  c.
   1941     </dd>
   1942     <dt>
   1943         {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_FILE_ID}
   1944     </dt>
   1945     <dd>
   1946         Mt m nh danh dng s ca nh cho mt lin lc th. Ni gi tr ny vi hng s
   1947         {@link android.provider.ContactsContract.DisplayPhoto#CONTENT_URI DisplayPhoto.CONTENT_URI}
   1948          nhn mt URI ni dung tr v mt tp nh n, ri gi
   1949         {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)
   1950         openAssetFileDescriptor()}  nhn mt iu khin (handle) cho tp nh.
   1951     </dd>
   1952     <dt>
   1953         {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_URI}
   1954     </dt>
   1955     <dd>
   1956         Mt URI ni dung tr trc tip ti tp nh cho nh c i din bi hng ny.
   1957         Gi {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)
   1958         openAssetFileDescriptor()} bng URI ny  nhn mt iu khin (handle) cho tp nh.
   1959     </dd>
   1960 </dl>
   1961 <h3 id="SocialStreamTables">S dng cc bng lung x hi</h3>
   1962 <p>
   1963     Nhng bng ny hot ng ging nh cc bng chnh khc trong Trnh cung cp Danh b, ngoi tr:
   1964 </p>
   1965     <ul>
   1966         <li>
   1967             Nhng bng ny yu cu quyn truy cp b sung.  c t chng, ng dng ca bn
   1968             phi c quyn {@code android.Manifest.permission#READ_SOCIAL_STREAM}. 
   1969             sa i chng, ng dng ca bn phi c quyn
   1970             {@code android.Manifest.permission#WRITE_SOCIAL_STREAM}.
   1971         </li>
   1972         <li>
   1973             i vi bng {@code android.provider.ContactsContract.StreamItems}, s hng
   1974             c lu gi cho mi lin lc th s b gii hn. Sau khi t n gii hn ny,
   1975             Trnh cung cp Danh b s to khong trng cho cc hng mc dng mi bng cch t ng xa
   1976             nhng hng c
   1977             {@code android.provider.ContactsContract.StreamItemsColumns#TIMESTAMP} lu nht.  nhn
   1978             gii hn, hy pht hnh mt truy vn ti URI ni dung
   1979             {@code android.provider.ContactsContract.StreamItems#CONTENT_LIMIT_URI}. Bn c th 
   1980             tt c cc tham i khc ngoi URI ni dung c t v <code>null</code>. Truy vn
   1981             tr v mt Con chy cha mt hng n, vi ct n
   1982             {@code android.provider.ContactsContract.StreamItems#MAX_ITEMS}.
   1983         </li>
   1984     </ul>
   1985 
   1986 <p>
   1987     Lp {@code android.provider.ContactsContract.StreamItems.StreamItemPhotos} nh ngha mt
   1988     bng con {@code android.provider.ContactsContract.StreamItemPhotos} cha cc hng nh
   1989     cho mt mc dng n.
   1990 </p>
   1991 <h3 id="SocialStreamInteraction">Tng tc t lung x hi</h3>
   1992 <p>
   1993     D liu t lung x hi c qun l bi Trnh cung cp Danh b, kt hp vi
   1994     ng dng danh b ca thit b, cung cp mt cch hiu qu  kt ni h thng mng x hi ca bn
   1995     vi cc lin lc hin ti. C sn nhng tnh nng sau:
   1996 </p>
   1997     <ul>
   1998         <li>
   1999             Bng cch ng b dch v mng x hi ca bn vi Trnh cung cp Danh b bng mt trnh iu hp
   2000             ng b, bn c th truy xut hot ng gn y i vi danh b ca mt ngi dng v lu gi n trong
   2001             cc bng {@code android.provider.ContactsContract.StreamItems} v
   2002             {@code android.provider.ContactsContract.StreamItemPhotos}  s dng sau.
   2003         </li>
   2004         <li>
   2005             Bn cnh vic ng b ho thng xuyn, bn c th kch khi trnh iu hp ng b ca mnh  truy xut
   2006             d liu b sung khi ngi dng chn mt lin lc  xem. iu ny cho php trnh iu hp ng b ca bn
   2007             truy xut nh  phn gii cao v cc mc dng gn y nht cho lin lc .
   2008         </li>
   2009         <li>
   2010             Bng cch ng k mt thng bo vi ng dng danh b ca thit b v Trnh cung cp
   2011             Danh b, bn c th <em>nhn</em> mt  nh khi mt lin lc c xem, v ti thi im ,
   2012             cp nht trng thi ca lin lc  t dch v ca bn. Phng php ny c th nhanh hn v s dng t
   2013             bng thng hn vic thc hin ng b y  vi mt trnh iu hp ng b.
   2014         </li>
   2015         <li>
   2016             Ngi dng c th thm mt lin lc vo dch v mng x hi ca mnh trong khi ang xem lin lc 
   2017             trong ng dng danh b ca thit b. Bn kch hot iu ny bng tnh nng "mi lin lc",
   2018            theo  cho php kt hp mt hot ng  thm mt lin lc hin c vo mng
   2019             ca bn, v mt tp XML  cung cp cho ng dng danh b ca thit b v
   2020             Trnh cung cp Danh b thng tin chi tit v ng dng ca bn.
   2021         </li>
   2022     </ul>
   2023 <p>
   2024     ng b ha thng xuyn cc mc dng vi Trnh cung cp Danh b ging nh
   2025     cc trng hp ng b ho khc.  tm hiu thm v ng b ho, hy xem phn
   2026     <a href="#SyncAdapters">Trnh iu hp ng b Trnh cung cp Danh b</a>. Vic ng k thng tin v
   2027     mi lin lc c  cp trong hai phn tip theo.
   2028 </p>
   2029 <h4>ng k  x l cc lt xem mng x hi</h4>
   2030 <p>
   2031      ng k  trnh iu hp ng b ca bn nhn thng bo khi ngi dng xem mt lin lc do
   2032     trnh iu hp ng b ca bn qun l:
   2033 </p>
   2034 <ol>
   2035     <li>
   2036         To mt tp c tn <code>contacts.xml</code> trong th mc <code>res/xml/</code>
   2037         ca d n ca bn. Nu  c tp ny, bn c th b qua bc ny.
   2038     </li>
   2039     <li>
   2040         Trong tp ny, hy thm phn t
   2041 <code>&lt;ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android"&gt;</code>.
   2042         Nu phn t ny  tn ti, bn c th b qua bc ny.
   2043     </li>
   2044     <li>
   2045          ng k mt dch v c thng bo khi ngi dng m trang chi tit ca mt lin lc trong
   2046         ng dng danh b ca thit b, hy thm thuc tnh
   2047         <code>viewContactNotifyService="<em>serviceclass</em>"</code> vo phn t, trong 
   2048         <code><em>serviceclass</em></code> l tn lp c p ng y  ca dch v
   2049         m s nhn  nh t ng dng danh b ca thit b. i vi dch v
   2050         trnh thng bo, hy s dng mt lp m rng {@link android.app.IntentService},  cho php dch v
   2051         nhn cc  nh. D liu trong  nh n cha URI ni dung ca lin lc
   2052         th m ngi dng  nhp vo. T dch v trnh thng bo, bn c th gn kt vi ri gi trnh iu hp ng b
   2053         ca bn  cp nht d liu cho lin lc th.
   2054     </li>
   2055 </ol>
   2056 <p>
   2057      ng k mt hot ng s c gi khi ngi dng nhp vo mt mc dng hay nh hoc c hai:
   2058 </p>
   2059 <ol>
   2060     <li>
   2061         To mt tp c tn <code>contacts.xml</code> trong th mc <code>res/xml/</code>
   2062         ca d n ca bn. Nu  c tp ny, bn c th b qua bc ny.
   2063     </li>
   2064     <li>
   2065         Trong tp ny, hy thm phn t
   2066 <code>&lt;ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android"&gt;</code>.
   2067         Nu phn t ny  tn ti, bn c th b qua bc ny.
   2068     </li>
   2069     <li>
   2070          ng k mt trong cc hot ng ca bn s x l khi ngi dng nhp vo mt mc dng trong
   2071         ng dng danh b ca thit b, hy thm thuc tnh
   2072         <code>viewStreamItemActivity="<em>activityclass</em>"</code> vo phn t , trong 
   2073         <code><em>activityclass</em></code> l tn lp c xc nh y  ca hot ng
   2074         m s nhn  nh t ng dng danh b ca thit b.
   2075     </li>
   2076     <li>
   2077          ng k mt trong cc hot ng ca bn s x l khi ngi dng nhp vo mt nh lung trong
   2078         ng dng danh b ca thit b, hy thm thuc tnh
   2079         <code>viewStreamItemPhotoActivity="<em>activityclass</em>"</code> vo phn t , trong 
   2080         <code><em>activityclass</em></code> l tn lp c xc nh y  ca hot ng
   2081         m s nhn  nh t ng dng danh b ca thit b.
   2082     </li>
   2083 </ol>
   2084 <p>
   2085     Phn t <code>&lt;ContactsAccountType&gt;</code> c m t chi tit hn trong mc
   2086     phn t <a href="#SocialStreamAcctType">&lt;ContactsAccountType&gt;</a>.
   2087 </p>
   2088 <p>
   2089      nh n cha URI ni dung ca mc hoc nh m ngi dng  nhp vo.
   2090      c cc hot ng ring cho cc mc vn bn v nh, hy s dng c hai thuc tnh trong cng tp.
   2091 </p>
   2092 <h4>Tng tc vi dch v mng x hi ca bn</h4>
   2093 <p>
   2094     Ngi dng khng phi ri ng dng danh b ca thit b  mi mt lin lc ti trang mng x hi
   2095     ca bn. Thay vo , bn c th thit t  ng dng danh b ca thit b gi mt  nh  mi
   2096     lin lc  ti mt trong cc hot ng ca mnh.  thit t iu ny:
   2097 </p>
   2098 <ol>
   2099     <li>
   2100         To mt tp c tn <code>contacts.xml</code> trong th mc <code>res/xml/</code>
   2101         ca d n ca bn. Nu  c tp ny, bn c th b qua bc ny.
   2102     </li>
   2103     <li>
   2104         Trong tp ny, hy thm phn t
   2105 <code>&lt;ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android"&gt;</code>.
   2106         Nu phn t ny  tn ti, bn c th b qua bc ny.
   2107     </li>
   2108     <li>
   2109         Thm cc thuc tnh sau:
   2110         <ul>
   2111             <li><code>inviteContactActivity="<em>activityclass</em>"</code></li>
   2112             <li>
   2113                 <code>inviteContactActionLabel="&#64;string/<em>invite_action_label</em>"</code>
   2114             </li>
   2115         </ul>
   2116         Gi tr <code><em>activityclass</em></code> l tn lp c xc nh y  ca hot ng
   2117         m s nhn c  nh. Gi tr <code><em>invite_action_label</em></code>
   2118         l mt xu vn bn c hin th trong menu <strong>Thm Kt ni</strong> trong ng dng danh b
   2119         ca thit b.
   2120     </li>
   2121 </ol>
   2122 <p class="note">
   2123     <strong>Lu :</strong> <code>ContactsSource</code> l mt tn tag khng c chp nhn i vi
   2124     <code>ContactsAccountType</code>.
   2125 </p>
   2126 <h3 id="ContactsFile">Tham chiu contacts.xml</h3>
   2127 <p>
   2128     Tp <code>contacts.xml</code> cha cc phn t XML c chc nng kim sot tng tc gia
   2129     trnh iu hp ng b v ng dng ca bn vi ng dng danh b v Trnh cung cp Danh b. Nhng
   2130     phn t ny c m t trong cc mc sau.
   2131 </p>
   2132 <h4 id="SocialStreamAcctType">Thnh phn &lt;ContactsAccountType&gt;</h4>
   2133 <p>
   2134     Phn t <code>&lt;ContactsAccountType&gt;</code> kim sot tng tc gia
   2135     ng dng ca bn vi ng dng danh b. N c nhng c php sau:
   2136 </p>
   2137 <pre>
   2138 &lt;ContactsAccountType
   2139         xmlns:android="http://schemas.android.com/apk/res/android"
   2140         inviteContactActivity="<em>activity_name</em>"
   2141         inviteContactActionLabel="<em>invite_command_text</em>"
   2142         viewContactNotifyService="<em>view_notify_service</em>"
   2143         viewGroupActivity="<em>group_view_activity</em>"
   2144         viewGroupActionLabel="<em>group_action_text</em>"
   2145         viewStreamItemActivity="<em>viewstream_activity_name</em>"
   2146         viewStreamItemPhotoActivity="<em>viewphotostream_activity_name</em>"&gt;
   2147 </pre>
   2148 <p>
   2149     <strong>cha trong:</strong>
   2150 </p>
   2151 <p>
   2152     <code>res/xml/contacts.xml</code>
   2153 </p>
   2154 <p>
   2155     <strong>c th cha:</strong>
   2156 </p>
   2157 <p>
   2158     <strong><code>&lt;ContactsDataKind&gt;</code></strong>
   2159 </p>
   2160 <p>
   2161     <strong>M t:</strong>
   2162 </p>
   2163 <p>
   2164     Khai bo cc thnh phn Android v nhn UI m cho php ngi dng mi mt trong cc lin lc ca mnh n
   2165     mt mng x hi, thng bo ngi dng khi mt trong cc lung mng x hi ca h c cp nht,
   2166     v.v.
   2167 </p>
   2168 <p>
   2169       rng tin t thuc tnh <code>android:</code> khng nht thit p dng cho cc thuc tnh
   2170     ca <code>&lt;ContactsAccountType&gt;</code>.
   2171 </p>
   2172 <p>
   2173     <strong>Thuc tnh:</strong>
   2174 </p>
   2175 <dl>
   2176     <dt>{@code inviteContactActivity}</dt>
   2177     <dd>
   2178         Tn lp c xc nh y  ca hot ng trong ng dng ca bn m bn mun
   2179         kch hot khi ngi dng chn <strong>Thm kt ni</strong> t ng dng danh b
   2180         ca thit b.
   2181     </dd>
   2182     <dt>{@code inviteContactActionLabel}</dt>
   2183     <dd>
   2184         Mt xu vn bn c hin th cho hot ng c quy nh trong
   2185         {@code inviteContactActivity}, trong menu <strong>Thm kt ni</strong>.
   2186         V d, bn c th s dng xu "Follow in my network". Bn c th s dng m nh danh
   2187         ti nguyn xu cho nhn ny.
   2188     </dd>
   2189     <dt>{@code viewContactNotifyService}</dt>
   2190     <dd>
   2191         Tn lp c xc nh y  ca mt dch v trong ng dng ca bn m s nhn c
   2192         thng bo khi ngi dng xem mt lin lc. Thng bo ny c gi t ng dng danh b
   2193         ca thit b; n cho php ng dng ca bn tm hon cc thao tc dng nhiu d liu ti
   2194         khi cn. V d, ng dng ca bn c th hi p li thng bo ny
   2195         bng cch c v hin th nh  phn gii cao ca danh b v cc mc dng mng x hi
   2196         gn y nht. Tnh nng ny c m t chi tit hn trong phn
   2197         <a href="#SocialStreamInteraction">Tng tc vi lung x hi</a>. Bn c th thy mt
   2198         v d v dch v thng bo trong tp <code>NotifierService.java</code> trong ng dng mu
   2199         <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">SampleSyncAdapter</a>
   2200 .
   2201     </dd>
   2202     <dt>{@code viewGroupActivity}</dt>
   2203     <dd>
   2204         Tn lp c xc nh y  ca mt hot ng trong ng dng ca bn m c th
   2205         hin th thng tin nhm. Khi ngi dng nhp vo nhn nhm trong ng dng danh b
   2206         ca thit b, UI cho hot ng ny s c hin th.
   2207     </dd>
   2208     <dt>{@code viewGroupActionLabel}</dt>
   2209     <dd>
   2210         Nhn m ng dng danh b hin th cho mt iu khin UI c cho php
   2211         ngi dng xem cc nhm trong ng dng ca bn.
   2212         <p>
   2213             V d, nu bn ci t ng dng Google+ trn thit b ca mnh v bn ng b
   2214             Google+ vi ng dng danh b, bn s thy cc vng trn Google+ c lit k thnh cc nhm
   2215             trong tab <strong>Nhm</strong> ca ng dng danh b ca bn. Nu bn nhp vo mt vng trn
   2216             Google+, bn s thy nhng ngi trong vng trn  c lit k thnh mt "nhm". Pha bn trn ca
   2217             hin th, bn s thy mt biu tng Google+; nu bn nhp vo , iu khin s chuyn sang ng dng
   2218             Google+. ng dng danh b lm iu ny bng
   2219             {@code viewGroupActivity}, bng cch s dng biu tng Google+ lm gi tr ca
   2220             {@code viewGroupActionLabel}.
   2221         </p>
   2222         <p>
   2223             Mt m nh danh ti nguyn xu c cho php cho thuc tnh ny.
   2224         </p>
   2225     </dd>
   2226     <dt>{@code viewStreamItemActivity}</dt>
   2227     <dd>
   2228         Tn lp c xc nh y  ca mt hot ng trong ng dng ca bn m
   2229         ng dng danh b ca thit b khi chy khi ngi dng nhp vo mt mc dng i vi mt lin lc th.
   2230     </dd>
   2231     <dt>{@code viewStreamItemPhotoActivity}</dt>
   2232     <dd>
   2233         Tn lp c xc nh y  ca mt hot ng trong ng dng ca bn m
   2234        ng dng danh b ca thit b khi chy khi ngi dng nhp vo mt nh trong mc dng
   2235         i vi mt lin lc th.
   2236     </dd>
   2237 </dl>
   2238 <h4 id="SocialStreamDataKind">Phn t &lt;ContactsDataKind&gt;</h4>
   2239 <p>
   2240     Phn t <code>&lt;ContactsDataKind&gt;</code> kim sot vic hin th cc hng
   2241     d liu ty chnh ca ng dng ca bn trong UI ca ng dng danh b. N c nhng c php sau:
   2242 </p>
   2243 <pre>
   2244 &lt;ContactsDataKind
   2245         android:mimeType="<em>MIMEtype</em>"
   2246         android:icon="<em>icon_resources</em>"
   2247         android:summaryColumn="<em>column_name</em>"
   2248         android:detailColumn="<em>column_name</em>"&gt;
   2249 </pre>
   2250 <p>
   2251     <strong>cha trong:</strong>
   2252 </p>
   2253 <code>&lt;ContactsAccountType&gt;</code>
   2254 <p>
   2255     <strong>M t:</strong>
   2256 </p>
   2257 <p>
   2258     S dng phn t ny  ng dng danh b hin th cc ni dung trong mt hng d liu ty chnh nh
   2259     mt phn chi tit ca mt lin lc th. Mi phn t con <code>&lt;ContactsDataKind&gt;</code>
   2260     ca <code>&lt;ContactsAccountType&gt;</code> i din cho mt kiu hng d liu ty chnh m trnh iu hp
   2261     ng b ca bn thm vo bng {@link android.provider.ContactsContract.Data}. Thm mt phn t
   2262     <code>&lt;ContactsDataKind&gt;</code> cho mi kiu MIME ty chnh m bn s dng. Bn khng phi
   2263     thm phn t nu c mt hng d liu ty chnh m bn khng mun hin th d liu.
   2264 </p>
   2265 <p>
   2266     <strong>Thuc tnh:</strong>
   2267 </p>
   2268 <dl>
   2269     <dt>{@code android:mimeType}</dt>
   2270     <dd>
   2271         Kiu MIME ty chnh m bn  nh ngha cho mt trong cc kiu hng d liu ty chnh ca bn trong bng
   2272         {@link android.provider.ContactsContract.Data}. V d, gi tr
   2273         <code>vnd.android.cursor.item/vnd.example.locationstatus</code> c th l mt kiu
   2274         MIME ty chnh cho mt hng d liu c chc nng ghi li v tr c bit n cui cng ca mt lin lc.
   2275     </dd>
   2276     <dt>{@code android:icon}</dt>
   2277     <dd>
   2278         Mt ti nguyn
   2279         <a href="{@docRoot}guide/topics/resources/drawable-resource.html">c th v ca Android</a>
   2280         m ng dng danh b hin th bn cnh d liu ca bn. S dng n  th hin vi
   2281         ngi dng rng d liu xut pht t dch v ca bn.
   2282     </dd>
   2283     <dt>{@code android:summaryColumn}</dt>
   2284     <dd>
   2285         Tn ct ca gi tr th nht trong hai gi tr c truy xut t hng d liu. Gi tr
   2286         c hin th l dng th nht ca mc nhp cho hng d liu ny. Dng th nht c
   2287         mc ch s dng lm bn tm tt d liu, nhng iu  l ty chn. Xem thm
   2288         <a href="#detailColumn">android:detailColumn</a>.
   2289     </dd>
   2290     <dt>{@code android:detailColumn}</dt>
   2291     <dd>
   2292         Tn ct ca gi tr th hai trong hai gi tr c truy xut t hng d liu. Gi tr
   2293         c hin th l dng th hai ca mc nhp cho hng d liu ny. Xem thm
   2294         {@code android:summaryColumn}.
   2295     </dd>
   2296 </dl>
   2297 <h2 id="AdditionalFeatures">Cc Tnh nng B sung ca Trnh cung cp Danh b</h2>
   2298 <p>
   2299     Bn cnh cc tnh nng chnh c m t trong cc phn trc, Trnh cung cp Danh b cn cung cp
   2300     nhng tnh nng hu ch sau khi lm vic vi d liu danh b:
   2301 </p>
   2302     <ul>
   2303        <li>Nhm lin lc</li>
   2304        <li>Tnh nng nh</li>
   2305     </ul>
   2306 <h3 id="Groups">Nhm lin lc</h3>
   2307 <p>
   2308     Trnh cung cp Danh b c th ty chn nh nhn cc b su tp lin lc c lin quan bng d liu
   2309     <strong>nhm</strong>. Nu my ch lin kt vi mt ti khon ngi dng
   2310     mun duy tr nhm, trnh iu hp ng b cho loi ti khon ca ti khon  s chuyn
   2311     d liu nhm gia Trnh cung cp Danh b v my ch. Khi ngi dng thm mt lin lc mi vo
   2312     my ch, trnh iu hp ng b phi thm nhm mi
   2313     vo bng {@link android.provider.ContactsContract.Groups}. Nhm hoc cc nhm m mt lin lc
   2314     th thuc v c lu gi trong bng {@link android.provider.ContactsContract.Data}, bng cch s dng
   2315     kiu MIME {@link android.provider.ContactsContract.CommonDataKinds.GroupMembership}.
   2316 </p>
   2317 <p>
   2318     Nu bn ang thit k mt trnh iu hp ng b m s thm d liu lin lc th t
   2319     my ch ti Trnh cung cp Danh b, v bn khng s dng cc nhm, khi  bn cn bo cho
   2320     Trnh cung cp lm cc d liu ca bn thy c. Trong on m c thc hin khi mt ngi dng thm mt ti khon
   2321     vo thit b, hy cp nht hng {@link android.provider.ContactsContract.Settings}
   2322     m Trnh cung cp Danh b thm cho ti khon. Trong hng ny, t gi tr ca ct
   2323     {@link android.provider.ContactsContract.SettingsColumns#UNGROUPED_VISIBLE
   2324     Settings.UNGROUPED_VISIBLE} thnh 1. Khi bn lm vy, Trnh cung cp Danh b s lun
   2325     lm cho d liu danh b ca bn thy c, ngay c khi bn khng s dng nhm.
   2326 </p>
   2327 <h3 id="Photos">nh lin lc</h3>
   2328 <p>
   2329     Bng {@link android.provider.ContactsContract.Data} lu gi nh thnh hng vi kiu MIME
   2330     {@link android.provider.ContactsContract.CommonDataKinds.Photo#CONTENT_ITEM_TYPE
   2331     Photo.CONTENT_ITEM_TYPE}. Ct
   2332     {@link android.provider.ContactsContract.RawContactsColumns#CONTACT_ID} ca hng c lin kt vi ct
   2333     {@code android.provider.BaseColumns#_ID} ca lin lc th m n thuc v.
   2334     Lp {@link android.provider.ContactsContract.Contacts.Photo} nh ngha mt bng con ca
   2335     {@link android.provider.ContactsContract.Contacts} cha thng tin nh v nh chnh
   2336     ca mt lin lc, y l nh chnh ca lin lc th chnh ca lin lc. Tng t,
   2337     lp {@link android.provider.ContactsContract.RawContacts.DisplayPhoto} nh ngha mt bng con
   2338     ca {@link android.provider.ContactsContract.RawContacts} cha thng tin nh i vi nh chnh
   2339     ca mt lin lc th.
   2340 </p>
   2341 <p>
   2342     Ti liu tham kho cho {@link android.provider.ContactsContract.Contacts.Photo} v
   2343     {@link android.provider.ContactsContract.RawContacts.DisplayPhoto} c cc v d v
   2344     vic truy xut thng tin nh. Khng c lp thun tin cho vic truy xut hnh thu nh
   2345     chnh i vi mt lin lc th, nhng bn c th gi mt truy vn ti bng
   2346     {@link android.provider.ContactsContract.Data}, chn
   2347     {@code android.provider.BaseColumns#_ID} ca lin lc th,
   2348     {@link android.provider.ContactsContract.CommonDataKinds.Photo#CONTENT_ITEM_TYPE
   2349     Photo.CONTENT_ITEM_TYPE}, v ct {@link android.provider.ContactsContract.Data#IS_PRIMARY}
   2350      tm hng nh chnh ca lin lc th.
   2351 </p>
   2352 <p>
   2353     D liu t lung x hi i vi mt ngi cng c th bao gm nh. Nhng nh ny c lu gi trong bng
   2354     {@code android.provider.ContactsContract.StreamItemPhotos}, c m t chi tit hn
   2355     trong phn <a href="#StreamPhotos">nh t lung x hi</a>.
   2356 </p>
   2357