1 page.title=Bn k khai ng dng 2 @jd:body 3 4 <div id="qv-wrapper"> 5 <div id="qv"> 6 7 <h2>Trong ti liu ny</h2> 8 <ol> 9 <li><a href="#filestruct">Cu trc ca Tp Bn k khai</a></li> 10 <li><a href="#filec">Cc Quy c Tp</a> 11 <li><a href="#filef">Cc Tnh nng Tp</a> 12 <ol> 13 <li><a href="#ifs">B lc nh</a></li> 14 <li><a href="#iconlabel">Biu tng v Nhn</a></li> 15 <li><a href="#perms">Quyn</a></li> 16 <li><a href="#libs">Th vin</a></li> 17 </ol></li> 18 </ol> 19 </div> 20 </div> 21 22 <p> 23 Mi ng dng u phi c mt tp AndroidManifest.xml (chnh xc l 24 tn gi ny) trong th mc gc ca mnh. <span itemprop="description">Tp bn k khai 25 trnh by nhng thng tin thit yu v ng dng ca bn vi h thng Android, 26 thng tin m h thng phi c trc khi c th chy bt k m no 27 ca ng dng.</span> Ngoi mt s mc ch khc, bn k khai thc hin nhng iu sau: 28 </p> 29 30 <ul> 31 <li>N t tn gi Java cho ng dng. 32 Tn gi ng vai tr nh mt m nhn din duy nht cho ng dng.</li> 33 34 <li>N m t cc thnh phn ca ng dng — hot ng, 35 dch v, hm nhn qung b, v trnh cung cp ni dung m ng dng 36 c son bi. N t tn cc lp trin khai tng thnh phn v 37 cng b cc kh nng ca chng (v d, nhng tin nhn {@link android.content.Intent 38 Intent} m chng c th x l). Nhng khai bo ny cho php h thng Android 39 bit cc thnh phn l g v chng c th c khi chy trong nhng iu kin no.</li> 40 41 <li>N xc nh nhng tin trnh no s lu tr cc thnh phn ng dng.</li> 42 43 <li>N khai bo cc quyn m ng dng phi c 44 truy cp cc phn c bo v ca API v tng tc vi cc ng dng khc.</li> 45 46 <li>N cng khai bo cc quyn m ng dng khc phi c 47 tng tc vi cc thnh phn ca ng dng.</li> 48 49 <li>N lit k cc lp {@link android.app.Instrumentation} cung cp 50 tnh nng to h s v cc thng tin khc khi ng dng ang chy. Nhng khai bo ny 51 ch xut hin trong bn k khai khi ng dng ang c pht trin v 52 th nghim; chng b loi b trc khi ng dng c cng b.</li> 53 54 <li>N khai bo mc ti thiu ca API Android m ng dng 55 yu cu.</li> 56 57 <li>N lit k cc th vin m ng dng phi c lin kt vi.</li> 58 </ul> 59 60 61 <h2 id="filestruct">Cu trc ca Tp Bn k khai</h2> 62 63 <p> 64 S bn di minh ha cu trc chung ca tp bn k khai v mi 65 phn t m n c th cha. Tng phn t, cng vi tt c thuc tnh 66 ca mnh, s c lp ti liu theo di y vo mt tp ring. xem thng tin 67 chi tit v mi phn t, hy nhp vo tn phn t trong s , 68 trong danh sch cc phn t theo th t ch ci m tun theo s , hoc trn bt k 69 ni dung no khc cp ti tn phn t. 70 </p> 71 72 <pre> 73 <?xml version="1.0" encoding="utf-8"?> 74 75 <a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a> 76 77 <a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission /></a> 78 <a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission /></a> 79 <a href="{@docRoot}guide/topics/manifest/permission-tree-element.html"><permission-tree /></a> 80 <a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group /></a> 81 <a href="{@docRoot}guide/topics/manifest/instrumentation-element.html"><instrumentation /></a> 82 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk /></a> 83 <a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><uses-configuration /></a> <!-- ##api level 3## --> 84 <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature /></a> <!-- ##api level 4## --> 85 <a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"><supports-screens /></a> <!-- ##api level 4## --> 86 <a href="{@docRoot}guide/topics/manifest/compatible-screens-element.html"><compatible-screens /></a> <!-- ##api level 9## --> 87 <a href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html"><supports-gl-texture /></a> <!-- ##api level 11## --> 88 89 <a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a> 90 91 <a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a> 92 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> 93 <a href="{@docRoot}guide/topics/manifest/action-element.html"><action /></a> 94 <a href="{@docRoot}guide/topics/manifest/category-element.html"><category /></a> 95 <a href="{@docRoot}guide/topics/manifest/data-element.html"><data /></a> 96 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 97 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 98 <a href="{@docRoot}guide/topics/manifest/activity-element.html"></activity></a> 99 100 <a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a> 101 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> . . . <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 102 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 103 <a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"></activity-alias></a> 104 105 <a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a> 106 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> . . . <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 107 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data/></a> 108 <a href="{@docRoot}guide/topics/manifest/service-element.html"></service></a> 109 110 <a href="{@docRoot}guide/topics/manifest/receiver-element.html"><receiver></a> 111 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> . . . <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 112 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 113 <a href="{@docRoot}guide/topics/manifest/receiver-element.html"></receiver></a> 114 115 <a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a> 116 <a href="{@docRoot}guide/topics/manifest/grant-uri-permission-element.html"><grant-uri-permission /></a> 117 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 118 <a href="{@docRoot}guide/topics/manifest/path-permission-element.html"><path-permission /></a> 119 <a href="{@docRoot}guide/topics/manifest/provider-element.html"></provider></a> 120 121 <a href="{@docRoot}guide/topics/manifest/uses-library-element.html"><uses-library /></a> 122 123 <a href="{@docRoot}guide/topics/manifest/application-element.html"></application></a> 124 125 <a href="{@docRoot}guide/topics/manifest/manifest-element.html"></manifest></a> 126 </pre> 127 128 <p> 129 Tt c phn t c th xut hin trong tp bn k khai c lit k bn di 130 theo th t ch ci. y l nhng phn t hp php duy nht; bn khng th 131 thm cc phn t hay thuc tnh ca chnh mnh. 132 </p> 133 134 <p style="margin-left: 2em"> 135 <code><a href="{@docRoot}guide/topics/manifest/action-element.html"><action></a></code> 136 <br/><code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 137 <br/><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a></code> 138 <br/><code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 139 <br/><code><a href="{@docRoot}guide/topics/manifest/category-element.html"><category></a></code> 140 <br/><code><a href="{@docRoot}guide/topics/manifest/data-element.html"><data></a></code> 141 <br/><code><a href="{@docRoot}guide/topics/manifest/grant-uri-permission-element.html"><grant-uri-permission></a></code> 142 <br/><code><a href="{@docRoot}guide/topics/manifest/instrumentation-element.html"><instrumentation></a></code> 143 <br/><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> 144 <br/><code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 145 <br/><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data></a></code> 146 <br/><code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 147 <br/><code><a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group></a></code> 148 <br/><code><a href="{@docRoot}guide/topics/manifest/permission-tree-element.html"><permission-tree></a></code> 149 <br/><code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code> 150 <br/><code><a href="{@docRoot}guide/topics/manifest/receiver-element.html"><receiver></a></code> 151 <br/><code><a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a></code> 152 <br/><code><a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"><supports-screens></a></code> <!-- ##api level 4## --> 153 <br/><code><a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><uses-configuration></a></code> <!-- ##api level 3## --> 154 <br/><code><a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a></code> <!-- ##api level 4## --> 155 <br/><code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html"><uses-library></a></code> 156 <br/><code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 157 <br/><code><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk></a></code> 158 </p> 159 160 161 162 163 <h2 id="filec">Cc Quy c Tp</h2> 164 165 <p> 166 Mt s quy c v quy tc p dng chung cho tt c cc phn t v thuc tnh 167 trong bn k khai: 168 </p> 169 170 <dl> 171 <dt><b>Phn t</b></dt> 172 <dd>Ch cc phn t 173 <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> v 174 <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 175 l bt buc phi c, chng u phi c mt v ch c th xy ra mt ln. 176 Hu ht cc phn t khc c th xy ra nhiu ln hoc khng xy ra — mc d t 177 nht mt vi trong s chng phi c mt bn k khai thc s c 178 ngha no . 179 180 <p> 181 Nu mt phn t cha bt k ni dung no, n c th cha cc phn t khc. 182 Tt c gi tr s c t thng qua thuc tnh, ch khng phi l d liu k t trong mt phn t. 183 </p> 184 185 <p> 186 Cc phn t cng cp thng khng theo th t. V d, cc phn t 187 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code>, 188 <code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>, v 189 <code><a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a></code> 190 c th c trn ln vi nhau theo bt k trnh t no. (Phn t 191 <code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a></code> 192 l trng hp ngoi l i vi quy tc ny: N phi tun theo 193 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 194 , i tng m n l b danh cho.) 195 </p></dd> 196 197 <dt><b>Thuc tnh</b></dt> 198 <dd>Theo cch hiu thng thng, tt c thuc tnh u mang tnh ty chn. Tuy nhin, c mt s thuc tnh 199 phi c quy nh cho mt phn t hon thnh mc ch ca n. S dng 200 ti liu lm hng dn. i vi nhng thuc tnh thc s ty chn, n cp ti mt gi tr 201 mc nh hoc thng bo iu g s xy ra nu khng c mt c t. 202 203 <p>Ngoi mt s thuc tnh ca phn t 204 <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 205 gc, tt c tn thuc tnh u bt u bng mt tin t {@code android:}— 206 v d, {@code android:alwaysRetainTaskState}. Do tin t ny 207 ph dng, ti liu thng b st n khi tham chiu ti cc thuc tnh 208 theo tn.</p></dd> 209 210 <dt><b>Khai bo tn lp</b></dt> 211 <dd>Nhiu thuc tnh tng ng vi cc i tng Java, bao gm cc phn t cho 212 chnh ng dng (phn t 213 <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 214 ) v cc thnh phn chnh ca n — hot ng 215 (<code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code>), 216 dch v 217 (<code><a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a></code>), 218 hm nhn qung b 219 (<code><a href="{@docRoot}guide/topics/manifest/receiver-element.html"><receiver></a></code>), 220 v trnh cung cp ni dung 221 (<code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>). 222 223 <p> 224 Nu bn nh ngha mt lp con nh vn lun lm i vi lp thnh phn 225 ({@link android.app.Activity}, {@link android.app.Service}, 226 {@link android.content.BroadcastReceiver}, v {@link android.content.ContentProvider}), 227 lp con s c khai bo thng qua mt thuc tnh {@code name}. Tn phi bao gm 228 ch nh gi y . 229 V d, mt lp con {@link android.app.Service} c th c khai bo nh sau: 230 </p> 231 232 <pre><manifest . . . > 233 <application . . . > 234 <service android:name="com.example.project.SecretService" . . . > 235 . . . 236 </service> 237 . . . 238 </application> 239 </manifest></pre> 240 241 <p> 242 Tuy nhin, do cch vit tc k, nu k t u tin ca xu l mt du chm, 243 xu s c ni vi tn gi ca ng dng (nh c quy nh bi 244 thuc tnh ca phn t <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 245 246 <code>, <a href="{@docRoot}guide/topics/manifest/manifest-element.html#package">package</a></code> 247 ). Cch gn sau cng ging nh trn: 248 </p> 249 250 <pre><manifest package="com.example.project" . . . > 251 <application . . . > 252 <service android:name=".SecretService" . . . > 253 . . . 254 </service> 255 . . . 256 </application> 257 </manifest></pre> 258 259 <p> 260 Khi khi ng mt thnh phn, Android s to mt thc th ca lp con c nu tn. 261 Nu lp con khng c quy nh, n s to mt thc th ca lp c s. 262 </p></dd> 263 264 <dt><b>Nhiu gi tr</b></dt> 265 <dd>Nu c th quy nh nhiu hn mt gi tr, phn t gn nh lun 266 c lp li, thay v lit k nhiu gi tr trong mt phn t duy nht. 267 V d, mt b lc nh c th lit k vi hnh ng: 268 269 <pre><intent-filter . . . > 270 <action android:name="android.intent.action.EDIT" /> 271 <action android:name="android.intent.action.INSERT" /> 272 <action android:name="android.intent.action.DELETE" /> 273 . . . 274 </intent-filter></pre></dd> 275 276 <dt><b>Gi tr ti nguyn</b></dt> 277 <dd>Mt s thuc tnh c cc gi tr c th c hin th vi ngi dng — v 278 d, mt nhn v mt biu tng cho mt hot ng. Gi tr ca nhng thuc tnh ny 279 cn c cc b ha v v th phi c thit t t mt ti nguyn hoc ch . Gi tr 280 ti nguyn c biu din theo nh dng sau,</p> 281 282 <p style="margin-left: 2em">{@code @[<i>gi</i>:]<i>kiu</i>:<i>tn</i>}</p> 283 284 <p> 285 trong <i>gi</i> c th c b qua nu ti nguyn nm trong cng gi 286 vi ng dng, <i>kiu</i> l kiu ca ti nguyn — chng hn nh "xu" hoc 287 — "v c" v <i>tn</i> l tn nhn bit ti nguyn c th. 288 V d: 289 </p> 290 291 <pre><activity android:icon="@drawable/smallPic" . . . ></pre> 292 293 <p> 294 Cc gi tr t mt ch c biu din theo cch tng t, nhng vi mt '{@code ?}' 295 thay v '{@code @}' u: 296 </p> 297 298 <p style="margin-left: 2em">{@code ?[<i>gi</i>:]<i>kiu</i>:<i>tn</i>} 299 </p></dd> 300 301 <dt><b>Gi tr xu</b></dt> 302 <dd>Trng hp gi tr ca mt thuc tnh l mt xu, phi s dng hai du xuyc ngc ('{@code \\}') 303 thot cc k t — v d, '{@code \\n}' i vi 304 mt dng tin tc hoc '{@code \\uxxxx}' i vi mt k t Unicode.</dd> 305 </dl> 306 307 308 <h2 id="filef">Cc Tnh nng Tp</h2> 309 310 <p> 311 Phn sau y m t cch phn nh mt s tnh nng ca Android 312 trong tp bn k khai. 313 </p> 314 315 316 <h3 id="ifs">B lc nh</h3> 317 318 <p> 319 Cc thnh phn ct li ca mt ng dng (hot ng, dch v v hm nhn 320 qung b) c kch hot bi <i> nh</i>. nh l mt 321 gi thng tin (mt i tng {@link android.content.Intent}) m t mt 322 hnh ng mong mun — bao gm d liu s c da trn, th loi ca 323 thnh phn m s thc hin hnh ng, v cc ch dn thch hp khc. 324 Android nh v mt thnh phn ph hp hi p nh, khi chy 325 mt thc th mi ca thnh phn nu cn, v chuyn cho n i tng 326 nh. 327 </p> 328 329 <p> 330 Cc thnh phn s qung co kh nng ca mnh — cc kiu nh m chng c th 331 hi p — thng qua <i>cc b lc nh</i>. Do h thng Android phi 332 tm hiu mt thnh phn c th x l nhng nh no trc khi khi chy thnh phn , 333 b lc nh c quy nh trong bn k khai nh l cc phn t 334 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> 335 . Mt thnh phn c th c nhiu b lc, mi b lc li m t 336 mt kh nng khc nhau. 337 </p> 338 339 <p> 340 Mt nh m cng khai nu tn mt thnh phn mc tiu s kch hot thnh phn ; 341 b lc khng c vai tr g y. Nhng mt nh m khng quy nh mt mc tiu 342 theo tn s ch c th kch hot thnh phn nu n c th chuyn qua mt trong cc b lc ca 343 thnh phn. 344 </p> 345 346 <p> 347 bit thng tin v cch cc i tng nh c kim tra thng qua b lc nh, 348 hy xem ti liu ring c tiu 349 <a href="{@docRoot}guide/components/intents-filters.html"> nh 350 v B lc nh</a>. 351 </p> 352 353 354 <h3 id="iconlabel">Biu tng v Nhn</h3> 355 356 <p> 357 Nhiu phn t c thuc tnh {@code icon} v {@code label} cho mt 358 biu tng nh v nhn vn bn m c th c hin th vi ngi dng. Mt s cng c thuc tnh 359 {@code description} cho vn bn gii trnh di hn m cng c th 360 c hin th trn mn hnh. V d, phn t 361 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 362 c c ba thuc tnh ny, v th khi ngi dng c hi xem c 363 cp quyn cho mt ng dng yu cu hay khng, biu tng th hin 364 quyn, tn ca quyn, v m t ni dung 365 ca quyn u c th c trnh by cho ngi dng xem. 366 </p> 367 368 <p> 369 Trong mi trng hp, biu tng v nhn c t trong mt phn t cha s tr thnh cc thit t 370 {@code icon} v {@code label} mc nh cho tt c phn t con ca b cha . 371 V th, biu tng v nhn c t trong phn t 372 <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 373 l biu tng v nhn mc nh cho tng thnh phn ca ng dng. 374 Tng t, biu tng v nhn c t cho mt thnh phn — v d, mt phn t 375 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 376 — s l cc ci t mc nh cho tng phn t 377 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> 378 ca thnh phn . Nu mt phn t 379 <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 380 thit t mt nhn, nhng hot ng v b lc nh ca n th khng, 381 nhn ng dng s c coi l nhn ca c hot ng v 382 b lc nh. 383 </p> 384 385 <p> 386 Biu tng v nhn c t cho mt b lc nh s c s dng biu din mt thnh phn 387 bt c khi no thnh phn c trnh by vi ngi dng thc hin chc nng 388 m b lc qung co. V d, mt b lc vi cc thit t 389 "{@code android.intent.action.MAIN}" v 390 "{@code android.intent.category.LAUNCHER}" qung co mt hot ng 391 l hot ng khi u mt ng dng — c th, l 392 hot ng s c hin th trong trnh khi chy ng dng. V th, biu tng v nhn 393 c t trong b lc l nhng ni dung c hin th trong trnh khi chy. 394 </p> 395 396 397 <h3 id="perms">Quyn</h3> 398 399 <p> 400 Mt <i>quyn</i> l s hn ch gii hn truy cp vo mt phn ca m 401 hoc vo d liu trn thit b. Gii hn ny c p t nhm bo v d liu 402 v m trng yu, c th b lm dng bp mo hoc lm hng tri nghim ngi dng. 403 </p> 404 405 <p> 406 Mi quyn c nhn bit bng mt nhn duy nht. Thng thng, nhn cho bit 407 hnh ng b hn ch. V d, sau y l mt s quyn c nh ngha 408 bi Android: 409 </p> 410 411 <p style="margin-left: 2em">{@code android.permission.CALL_EMERGENCY_NUMBERS} 412 <br/>{@code android.permission.READ_OWNER_DATA} 413 <br/>{@code android.permission.SET_WALLPAPER} 414 <br/>{@code android.permission.DEVICE_POWER}</p> 415 416 <p> 417 Mt tnh nng c th c bo v bi nhiu nht mt quyn. 418 </p> 419 420 <p> 421 Nu mt ng dng cn truy cp vo mt tnh nng c bo v bi mt quyn, 422 n phi khai bo rng n yu cu quyn cng vi mt phn t 423 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 424 trong bn k khai. Lc , khi ng dng c ci t trn 425 thit b, trnh ci t s xc nh xem c cp quyn 426 c yu cu hay khng bng cch kim tra cc thm quyn k chng ch 427 ca ng dng v trong mt s trng hp, bng cch hi ngi dng. 428 Nu quyn c cp, ng dng c th s dng cc tnh nng 429 c bo v. Nu khng, vic th truy cp nhng tnh nng s tht bi 430 m khng c bt k thng bo no cho ngi dng. 431 </p> 432 433 <p> 434 Mt ng dng cng c th bo v cc thnh phn ca chnh n (hot ng, dch v, 435 hm nhn qung b v trnh cung cp ni dung) bng cc quyn. N c th s dng 436 bt k quyn no c nh ngha bi Android (c lit k trong 437 {@link android.Manifest.permission android.Manifest.permission}) hoc c khai bo 438 bi cc ng dng khc. Hoc n c th t nh ngha quyn ca mnh. Mt quyn mi c khai bo 439 bng phn t 440 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 441 . V d, mt hot ng c th c bo v nh sau: 442 </p> 443 444 <pre> 445 <manifest . . . > 446 <permission android:name="com.example.project.DEBIT_ACCT" . . . /> 447 <uses-permission android:name="com.example.project.DEBIT_ACCT" /> 448 . . . 449 <application . . .> 450 <activity android:name="com.example.project.FreneticActivity" 451 android:permission="com.example.project.DEBIT_ACCT" 452 . . . > 453 . . . 454 </activity> 455 </application> 456 </manifest> 457 </pre> 458 459 <p> 460 Lu rng trong v d ny, quyn {@code DEBIT_ACCT} khng ch 461 c khai bo bng phn t 462 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 463 , vic s dng quyn cng c yu cu bng phn t 464 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 465 . Phi yu cu s dng quyn cc thnh phn khc ca 466 ng dng nhm khi chy hot ng c bo v, mc d vic bo v 467 do chnh ng dng p t. 468 </p> 469 470 <p> 471 Trong cng v d ny, nu thuc tnh {@code permission} c t thnh mt quyn 472 c khai bo ni khc 473 (chng hn nh {@code android.permission.CALL_EMERGENCY_NUMBERS}, s khng 474 cn phi khai bo li n bng mt phn t 475 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 476 . Tuy nhin, s vn cn phi yu cu s dng n bng 477 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code>. 478 </p> 479 480 <p> 481 Phn t 482 <code><a href="{@docRoot}guide/topics/manifest/permission-tree-element.html"><permission-tree></a></code> 483 s khai bo mt vng tn cho nhm quyn m s c nh ngha trong 484 m. V 485 <code><a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group></a></code> 486 s nh ngha mt nhn cho mt tp hp quyn (c c khai bo trong bn k khai bng phn t 487 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 488 v c khai bo ch khc). N ch nh hng ti cch cc quyn c 489 nhm li khi c trnh by vi ngi dng. Phn t 490 <code><a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group></a></code> 491 khng quy nh nhng quyn no thuc v nhm; 492 n ch t cho nhm mt ci tn. Mt quyn c t vo nhm 493 bng cch gn tn nhm vi thuc tnh ca phn t 494 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 495 , 496 <code><a href="{@docRoot}guide/topics/manifest/permission-element.html#pgroup">permissionGroup</a></code> 497 . 498 </p> 499 500 501 <h3 id="libs">Th vin</h3> 502 503 <p> 504 Mi ng dng u c lin kt vi th vin Android mc nh, n 505 bao gm cc gi c bn xy dng ng dng (bng cc lp thng dng 506 chng hn nh Hot ng, Dch v, nh, Dng xem, Nt, ng dng, Trnh cung cp Ni dung, 507 v.v.). 508 </p> 509 510 <p> 511 Tuy nhin, mt s gi nm trong th vin ca chnh mnh. Nu ng dng ca bn 512 s dng m t bt k gi no trong nhng gi ny, n phi cng khai yu cu c lin kt 513 vi chng. Bn k khai phi cha mt phn t 514 <code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html"><uses-library></a></code> 515 ring t tn cho tng th vin. (Tn th vin c th c tm thy trong ti liu 516 ca gi.) 517 </p> 518