1 page.title= 2 @jd:body 3 <div id="qv-wrapper"> 4 <div id="qv"> 5 <!-- In this document --> 6 <h2> </h2> 7 <ol> 8 <li> 9 <a href="#Basics"></a> 10 <ol> 11 <li> 12 <a href="#ClientProvider"> </a> 13 </li> 14 <li> 15 <a href="#ContentURIs">URI </a> 16 </li> 17 </ol> 18 </li> 19 <li> 20 <a href="#SimpleQuery"> </a> 21 <ol> 22 <li> 23 <a href="#RequestPermissions"> </a> 24 </li> 25 <li> 26 <a href="#Query"> </a> 27 </li> 28 <li> 29 <a href="#DisplayResults"> </a> 30 </li> 31 <li> 32 <a href="#GettingResults"> </a> 33 </li> 34 </ol> 35 </li> 36 <li> 37 <a href="#Permissions"> </a> 38 </li> 39 <li> 40 <a href="#Modifications">, </a> 41 <ol> 42 <li> 43 <a href="#Inserting"> </a> 44 </li> 45 <li> 46 <a href="#Updating"> </a> 47 </li> 48 <li> 49 <a href="#Deleting"> </a> 50 </li> 51 </ol> 52 </li> 53 <li> 54 <a href="#DataTypes"> </a> 55 </li> 56 <li> 57 <a href="#AltForms"> </a> 58 <ol> 59 <li> 60 <a href="#Batch"> </a> 61 </li> 62 <li> 63 <a href="#Intents"> </a> 64 </li> 65 </ol> 66 </li> 67 <li> 68 <a href="#ContractClasses">-</a> 69 </li> 70 <li> 71 <a href="#MIMETypeReference"> MIME</a> 72 </li> 73 </ol> 74 75 <!-- Key Classes --> 76 <h2> </h2> 77 <ol> 78 <li> 79 {@link android.content.ContentProvider} 80 </li> 81 <li> 82 {@link android.content.ContentResolver} 83 </li> 84 <li> 85 {@link android.database.Cursor} 86 </li> 87 <li> 88 {@link android.net.Uri} 89 </li> 90 </ol> 91 92 <!-- Related Samples --> 93 <h2> </h2> 94 <ol> 95 <li> 96 <a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/List2.html"> 97 Cursor (People)</a> 98 </li> 99 <li> 100 <a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html"> 101 Cursor (Phones)</a> 102 </li> 103 </ol> 104 105 <!-- See also --> 106 <h2>. </h2> 107 <ol> 108 <li> 109 <a href="{@docRoot}guide/topics/providers/content-provider-creating.html"> 110 </a> 111 </li> 112 <li> 113 <a href="{@docRoot}guide/topics/providers/calendar-provider.html"> 114 </a> 115 </li> 116 </ol> 117 </div> 118 </div> 119 120 <!-- Intro paragraphs --> 121 <p> 122 . 123 Android, 124 . , 125 . 126 , , 127 . 128 </p> 129 <p> 130 , : 131 </p> 132 <ul> 133 <li> ;</li> 134 <li>API, ;</li> 135 <li>API, ;</li> 136 <li> API, .</li> 137 </ul> 138 139 <!-- Basics --> 140 <h2 id="Basics"></h2> 141 <p> 142 , 143 . 144 , , 145 . 146 </p> 147 <p> 148 Android , 149 , . 1 , 150 . 151 </p> 152 <p class="table-caption"> 153 <strong>1.</strong> . 154 </p> 155 <table id="table1" style="width: 50%;"> 156 <tr> 157 <th style="width:20%" align="center" scope="col">word</th> 158 <th style="width:20%" align="center" scope="col">app id</th> 159 <th style="width:20%" align="center" scope="col">frequency</th> 160 <th style="width:20%" align="center" scope="col">locale</th> 161 <th style="width:20%" align="center" scope="col">_ID</th> 162 </tr> 163 <tr> 164 <td align="center" scope="row">mapreduce</td> 165 <td align="center">user1</td> 166 <td align="center">100</td> 167 <td align="center">en_US</td> 168 <td align="center">1</td> 169 </tr> 170 <tr> 171 <td align="center" scope="row">precompiler</td> 172 <td align="center">user14</td> 173 <td align="center">200</td> 174 <td align="center">fr_FR</td> 175 <td align="center">2</td> 176 </tr> 177 <tr> 178 <td align="center" scope="row">applet</td> 179 <td align="center">user2</td> 180 <td align="center">225</td> 181 <td align="center">fr_CA</td> 182 <td align="center">3</td> 183 </tr> 184 <tr> 185 <td align="center" scope="row">const</td> 186 <td align="center">user1</td> 187 <td align="center">255</td> 188 <td align="center">pt_BR</td> 189 <td align="center">4</td> 190 </tr> 191 <tr> 192 <td align="center" scope="row">int</td> 193 <td align="center">user5</td> 194 <td align="center">100</td> 195 <td align="center">en_UK</td> 196 <td align="center">5</td> 197 </tr> 198 </table> 199 <p> 200 1 , 201 . , 202 , , . , 203 . , <code>locale</code>. 204 <code>_ID</code> , 205 . 206 </p> 207 <p class="note"> 208 <strong>.</strong> , 209 <code>_ID</code> , . , 210 {@link android.widget.ListView}, 211 <code>_ID</code>. 212 <a href="#DisplayResults"> </a>. 213 </p> 214 <h3 id="ClientProvider"> </h3> 215 <p> 216 217 {@link android.content.ContentResolver}. , 218 , 219 {@link android.content.ContentProvider}. 220 {@link android.content.ContentResolver} 221 CRUD ( create, retrieve, update, delete [, , ]) . 222 </p> 223 <p> 224 {@link android.content.ContentResolver} 225 {@link android.content.ContentProvider} , 226 , . 227 {@link android.content.ContentProvider} 228 . 229 </p> 230 <p class="note"> 231 <strong>.</strong> 232 . 233 <a href="#Permissions"> </a>. 234 </p> 235 <p> 236 , , , 237 {@link android.content.ContentResolver#query ContentResolver.query()}. 238 , {@link android.content.ContentResolver#query query()} 239 {@link android.content.ContentProvider#query ContentProvider.query()}, 240 . 241 {@link android.content.ContentResolver#query ContentResolver.query()}. 242 <p> 243 <pre> 244 // Queries the user dictionary and returns results 245 mCursor = getContentResolver().query( 246 UserDictionary.Words.CONTENT_URI, // The content URI of the words table 247 mProjection, // The columns to return for each row 248 mSelectionClause // Selection criteria 249 mSelectionArgs, // Selection criteria 250 mSortOrder); // The sort order for the returned rows 251 </pre> 252 <p> 253 2 254 {@link android.content.ContentResolver#query 255 query(Uri,projection,selection,selectionArgs,sortOrder)} SQL- SELECT. 256 </p> 257 <p class="table-caption"> 258 <strong>2.</strong> query() SQL-. 259 </p> 260 <table id="table2" style="width: 75%;"> 261 <tr> 262 <th style="width:25%" align="center" scope="col"> query()</th> 263 <th style="width:25%" align="center" scope="col">/ SELECT</th> 264 <th style="width:50%" align="center" scope="col"></th> 265 </tr> 266 <tr> 267 <td align="center"><code>Uri</code></td> 268 <td align="center"><code>FROM <em>table_name</em></code></td> 269 <td><code>Uri</code> <em>table_name</em> .</td> 270 </tr> 271 <tr> 272 <td align="center"><code>projection</code></td> 273 <td align="center"><code><em>col,col,col,...</em></code></td> 274 <td> 275 <code>projection</code> , 276 . 277 </td> 278 </tr> 279 <tr> 280 <td align="center"><code>selection</code></td> 281 <td align="center"><code>WHERE <em>col</em> = <em>value</em></code></td> 282 <td><code>selection</code> .</td> 283 </tr> 284 <tr> 285 <td align="center"><code>selectionArgs</code></td> 286 <td align="center"> 287 ( . <code>?</code> 288 ). 289 </td> 290 </tr> 291 <tr> 292 <td align="center"><code>sortOrder</code></td> 293 <td align="center"><code>ORDER BY <em>col,col,...</em></code></td> 294 <td> 295 <code>sortOrder</code> 296 {@link android.database.Cursor}. 297 </td> 298 </tr> 299 </table> 300 <h3 id="ContentURIs">URI </h3> 301 <p> 302 <strong>URI </strong> URI, . URI 303 ( <strong></strong>) 304 , (<strong></strong>). 305 URI 306 . 307 </p> 308 <p> 309 310 {@link android.provider.UserDictionary.Words#CONTENT_URI} URI 311 words . {@link android.content.ContentResolver} 312 URI 313 . {@link android.content.ContentResolver} 314 315 . 316 </p> 317 <p> 318 {@link android.content.ContentProvider} URI , , 319 . <strong></strong> . 320 </p> 321 <p> 322 URI words : 323 </p> 324 <pre> 325 content://user_dictionary/words 326 </pre> 327 <p> 328 <code>user_dictionary</code> , 329 <code>words</code> . 330 <code>content://</code> (<strong></strong>) ; 331 , URI . 332 </p> 333 <p> 334 335 URI. , , <code>_ID</code> 336 <code>4</code>, URI : 337 </p> 338 <pre> 339 Uri singleUri = ContentUris.withAppendedId(UserDictionary.Words.CONTENT_URI,4); 340 </pre> 341 <p> 342 , 343 . 344 </p> 345 <p class="note"> 346 <strong>.</strong> {@link android.net.Uri} {@link android.net.Uri.Builder} 347 URI . {@link android.content.ContentUris} 348 349 URI. URI UserDictionary {@link android.content.ContentUris#withAppendedId 350 withAppendedId()}. 351 </p> 352 353 354 <!-- Retrieving Data from the Provider --> 355 <h2 id="SimpleQuery"> </h2> 356 <p> 357 358 . 359 </p> 360 <p class="note"> 361 , , 362 {@link android.content.ContentResolver#query ContentResolver.query()} . 363 . 364 {@link android.content.CursorLoader}, 365 366 <a href="{@docRoot}guide/components/loaders.html"></a>. , ; 367 . 368 </p> 369 <p> 370 , . 371 </p> 372 <ol> 373 <li> 374 . 375 </li> 376 <li> 377 , . 378 </li> 379 </ol> 380 <h3 id="RequestPermissions"> </h3> 381 <p> 382 , 383 . ; , 384 , . 385 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 386 , 387 . , 388 . , 389 . 390 </p> 391 <p> 392 , 393 , 394 . 395 </p> 396 <p> 397 398 <a href="#Permissions"> </a>. 399 </p> 400 <p> 401 402 <code>android.permission.READ_USER_DICTIONARY</code> , 403 , , . 404 </p> 405 <!-- Constructing the query --> 406 <h3 id="Query"> </h3> 407 <p> 408 . 409 : 410 </p> 411 <pre class="prettyprint"> 412 413 // A "projection" defines the columns that will be returned for each row 414 String[] mProjection = 415 { 416 UserDictionary.Words._ID, // Contract class constant for the _ID column name 417 UserDictionary.Words.WORD, // Contract class constant for the word column name 418 UserDictionary.Words.LOCALE // Contract class constant for the locale column name 419 }; 420 421 // Defines a string to contain the selection clause 422 String mSelectionClause = null; 423 424 // Initializes an array to contain selection arguments 425 String[] mSelectionArgs = {""}; 426 427 </pre> 428 <p> 429 430 {@link android.content.ContentResolver#query ContentResolver.query()} ( 431 ): SQL-. 432 , , . 433 </p> 434 <p> 435 , , <strong></strong> 436 ( <code>mProjection</code>). 437 </p> 438 <p> 439 , , 440 . , 441 ( <code>mSelectionClause</code>). 442 <code>?</code>, ( 443 <code>mSelectionArgs</code>). 444 </p> 445 <p> 446 , , 447 <code>null</code>, , . , 448 <code>UserDictionary.Words.WORD + " = ?"</code>, 449 . 450 </p> 451 <pre class="prettyprint"> 452 /* 453 * This defines a one-element String array to contain the selection argument. 454 */ 455 String[] mSelectionArgs = {""}; 456 457 // Gets a word from the UI 458 mSearchString = mSearchWord.getText().toString(); 459 460 // Remember to insert code here to check for invalid or malicious input. 461 462 // If the word is the empty string, gets everything 463 if (TextUtils.isEmpty(mSearchString)) { 464 // Setting the selection clause to null will return all words 465 mSelectionClause = null; 466 mSelectionArgs[0] = ""; 467 468 } else { 469 // Constructs a selection clause that matches the word that the user entered. 470 mSelectionClause = UserDictionary.Words.WORD + " = ?"; 471 472 // Moves the user's input string to the selection arguments. 473 mSelectionArgs[0] = mSearchString; 474 475 } 476 477 // Does a query against the table and returns a Cursor object 478 mCursor = getContentResolver().query( 479 UserDictionary.Words.CONTENT_URI, // The content URI of the words table 480 mProjection, // The columns to return for each row 481 mSelectionClause // Either null, or the word the user entered 482 mSelectionArgs, // Either empty, or the string the user entered 483 mSortOrder); // The sort order for the returned rows 484 485 // Some providers return null if an error occurs, others throw an exception 486 if (null == mCursor) { 487 /* 488 * Insert code here to handle the error. Be sure not to use the cursor! You may want to 489 * call android.util.Log.e() to log this error. 490 * 491 */ 492 // If the Cursor is empty, the provider found no matches 493 } else if (mCursor.getCount() < 1) { 494 495 /* 496 * Insert code here to notify the user that the search was unsuccessful. This isn't necessarily 497 * an error. You may want to offer the user the option to insert a new row, or re-type the 498 * search term. 499 */ 500 501 } else { 502 // Insert code here to do something with the results 503 504 } 505 </pre> 506 <p> 507 SQL: 508 </p> 509 <pre> 510 SELECT _ID, word, locale FROM words WHERE word = <userinput> ORDER BY word ASC; 511 </pre> 512 <p> 513 SQL - . 514 </p> 515 <h4 id="Injection"> </h4> 516 <p> 517 , , SQL, 518 SQL SQL. 519 </p> 520 <p> 521 : 522 </p> 523 <pre> 524 // Constructs a selection clause by concatenating the user's input to the column name 525 String mSelectionClause = "var = " + mUserInput; 526 </pre> 527 <p> 528 , SQL SQL. 529 , nothing; DROP TABLE *; <code>mUserInput</code>, 530 : <code>var = nothing; DROP TABLE *;</code>. 531 SQL, , 532 SQLite ( 533 <a href="http://en.wikipedia.org/wiki/SQL_injection"> SQL</a>). 534 </p> 535 <p> 536 , , <code>?</code> 537 , . 538 SQL. 539 SQL, SQL. 540 , , : 541 </p> 542 <pre> 543 // Constructs a selection clause with a replaceable parameter 544 String mSelectionClause = "var = ?"; 545 </pre> 546 <p> 547 : 548 </p> 549 <pre> 550 // Defines an array to contain the selection arguments 551 String[] selectionArgs = {""}; 552 </pre> 553 <p> 554 : 555 </p> 556 <pre> 557 // Sets the selection argument to the user's input 558 selectionArgs[0] = mUserInput; 559 </pre> 560 <p> 561 , <code>?</code> , 562 , 563 SQL. 564 </p> 565 <!-- Displaying the results --> 566 <h3 id="DisplayResults"> </h3> 567 <p> 568 {@link android.content.ContentResolver#query ContentResolver.query()} 569 {@link android.database.Cursor}, , 570 , . 571 {@link android.database.Cursor} 572 . {@link android.database.Cursor} 573 , , , 574 . {@link android.database.Cursor} 575 - 576 {@link android.database.Cursor}, , . 577 </p> 578 <p class="note"> 579 <strong>.</strong> 580 , . , , 581 . 582 </p> 583 <p> 584 , , , 585 {@link android.database.Cursor}, 586 {@link android.database.Cursor#getCount Cursor.getCount()} 0 ( cursor). 587 </p> 588 <p> 589 . 590 <code>null</code> {@link java.lang.Exception}. 591 </p> 592 <p> 593 {@link android.database.Cursor} , 594 {@link android.database.Cursor} {@link android.widget.ListView} 595 {@link android.widget.SimpleCursorAdapter}. 596 </p> 597 <p> 598 . 599 {@link android.widget.SimpleCursorAdapter}, {@link android.database.Cursor}, 600 , 601 {@link android.widget.ListView}: 602 </p> 603 <pre class="prettyprint"> 604 // Defines a list of columns to retrieve from the Cursor and load into an output row 605 String[] mWordListColumns = 606 { 607 UserDictionary.Words.WORD, // Contract class constant containing the word column name 608 UserDictionary.Words.LOCALE // Contract class constant containing the locale column name 609 }; 610 611 // Defines a list of View IDs that will receive the Cursor columns for each row 612 int[] mWordListItems = { R.id.dictWord, R.id.locale}; 613 614 // Creates a new SimpleCursorAdapter 615 mCursorAdapter = new SimpleCursorAdapter( 616 getApplicationContext(), // The application's Context object 617 R.layout.wordlistrow, // A layout in XML for one row in the ListView 618 mCursor, // The result from the query 619 mWordListColumns, // A string array of column names in the cursor 620 mWordListItems, // An integer array of view IDs in the row layout 621 0); // Flags (usually none are needed) 622 623 // Sets the adapter for the ListView 624 mWordList.setAdapter(mCursorAdapter); 625 </pre> 626 <p class="note"> 627 <strong>.</strong> {@link android.widget.ListView} 628 {@link android.database.Cursor}, cursor <code>_ID</code>. 629 <code>_ID</code> 630 words, {@link android.widget.ListView} . 631 , 632 <code>_ID</code>. 633 </p> 634 635 <!-- Getting data from query results --> 636 <h3 id="GettingResults"> </h3> 637 <p> 638 , , . , 639 , 640 . {@link android.database.Cursor}: 641 </p> 642 <pre class="prettyprint"> 643 644 // Determine the column index of the column named "word" 645 int index = mCursor.getColumnIndex(UserDictionary.Words.WORD); 646 647 /* 648 * Only executes if the cursor is valid. The User Dictionary Provider returns null if 649 * an internal error occurs. Other providers may throw an Exception instead of returning null. 650 */ 651 652 if (mCursor != null) { 653 /* 654 * Moves to the next row in the cursor. Before the first movement in the cursor, the 655 * "row pointer" is -1, and if you try to retrieve data at that position you will get an 656 * exception. 657 */ 658 while (mCursor.moveToNext()) { 659 660 // Gets the value from the column. 661 newWord = mCursor.getString(index); 662 663 // Insert code here to process the retrieved word. 664 665 ... 666 667 // end of while loop 668 } 669 } else { 670 671 // Insert code here to report an error if the cursor is null or the provider threw an exception. 672 } 673 </pre> 674 <p> 675 {@link android.database.Cursor} get 676 . , 677 {@link android.database.Cursor#getString getString()}. 678 {@link android.database.Cursor#getType getType()}, , 679 . 680 </p> 681 682 683 <!-- Requesting permissions --> 684 <h2 id="Permissions"> </h2> 685 <p> 686 , 687 . , , 688 . 689 , . 690 . 691 </p> 692 <p> 693 , 694 . 695 , . 696 </p> 697 <p> 698 , 699 <code>android.permission.READ_USER_DICTIONARY</code>. 700 <code>android.permission.WRITE_USER_DICTIONARY</code> 701 , . 702 </p> 703 <p> 704 , , 705 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 706 . Android 707 , . 708 ; , 709 . 710 </p> 711 <p> 712 713 714 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code>: 715 </p> 716 <pre> 717 <uses-permission android:name="android.permission.READ_USER_DICTIONARY"> 718 </pre> 719 <p> 720 721 <a href="{@docRoot}guide/topics/security/security.html"> </a>. 722 </p> 723 724 725 <!-- Inserting, Updating, and Deleting Data --> 726 <h2 id="Modifications">, </h2> 727 <p> 728 , , 729 {@link android.content.ContentProvider} . 730 {@link android.content.ContentResolver}, , 731 {@link android.content.ContentProvider}. 732 . 733 </p> 734 <h3 id="Inserting"> </h3> 735 <p> 736 737 738 {@link android.content.ContentResolver#insert ContentResolver.insert()}. URI . 739 : 740 </p> 741 <pre class="prettyprint"> 742 // Defines a new Uri object that receives the result of the insertion 743 Uri mNewUri; 744 745 ... 746 747 // Defines an object to contain the new values to insert 748 ContentValues mNewValues = new ContentValues(); 749 750 /* 751 * Sets the values of each column and inserts the word. The arguments to the "put" 752 * method are "column name" and "value" 753 */ 754 mNewValues.put(UserDictionary.Words.APP_ID, "example.user"); 755 mNewValues.put(UserDictionary.Words.LOCALE, "en_US"); 756 mNewValues.put(UserDictionary.Words.WORD, "insert"); 757 mNewValues.put(UserDictionary.Words.FREQUENCY, "100"); 758 759 mNewUri = getContentResolver().insert( 760 UserDictionary.Word.CONTENT_URI, // the user dictionary content URI 761 mNewValues // the values to insert 762 ); 763 </pre> 764 <p> 765 {@link android.content.ContentValues}, 766 cursor . 767 , , 768 <code>null</code> {@link android.content.ContentValues#putNull ContentValues.putNull()}. 769 </p> 770 <p> 771 <code>_ID</code>, 772 . <code>_ID</code> 773 . . 774 </p> 775 <p> 776 URI , <code>newUri</code>, 777 : 778 </p> 779 <pre> 780 content://user_dictionary/words/<id_value> 781 </pre> 782 <p> 783 <code><id_value></code> <code>_ID</code> . 784 URI , 785 . 786 </p> 787 <p> 788 <code>_ID</code> {@link android.net.Uri}, 789 {@link android.content.ContentUris#parseId ContentUris.parseId()}. 790 </p> 791 <h3 id="Updating"> </h3> 792 <p> 793 , {@link android.content.ContentValues} 794 ( , ) ( , ). 795 796 {@link android.content.ContentResolver#update ContentResolver.update()}. 797 {@link android.content.ContentValues} . , 798 <code>null</code>. 799 </p> 800 <p> 801 , en, 802 <code>null</code>. , : 803 </p> 804 <pre> 805 // Defines an object to contain the updated values 806 ContentValues mUpdateValues = new ContentValues(); 807 808 // Defines selection criteria for the rows you want to update 809 String mSelectionClause = UserDictionary.Words.LOCALE + "LIKE ?"; 810 String[] mSelectionArgs = {"en_%"}; 811 812 // Defines a variable to contain the number of updated rows 813 int mRowsUpdated = 0; 814 815 ... 816 817 /* 818 * Sets the updated value and updates the selected words. 819 */ 820 mUpdateValues.putNull(UserDictionary.Words.LOCALE); 821 822 mRowsUpdated = getContentResolver().update( 823 UserDictionary.Words.CONTENT_URI, // the user dictionary content URI 824 mUpdateValues // the columns to update 825 mSelectionClause // the column to select on 826 mSelectionArgs // the value to compare to 827 ); 828 </pre> 829 <p> 830 831 {@link android.content.ContentResolver#update ContentResolver.update()}. 832 <a href="#Injection"> </a>. 833 </p> 834 <h3 id="Deleting"> </h3> 835 <p> 836 : , 837 , . 838 appid user. 839 . 840 </p> 841 <pre> 842 843 // Defines selection criteria for the rows you want to delete 844 String mSelectionClause = UserDictionary.Words.APP_ID + " LIKE ?"; 845 String[] mSelectionArgs = {"user"}; 846 847 // Defines a variable to contain the number of rows deleted 848 int mRowsDeleted = 0; 849 850 ... 851 852 // Deletes the words that match the selection criteria 853 mRowsDeleted = getContentResolver().delete( 854 UserDictionary.Words.CONTENT_URI, // the user dictionary content URI 855 mSelectionClause // the column to select on 856 mSelectionArgs // the value to compare to 857 ); 858 </pre> 859 <p> 860 861 {@link android.content.ContentResolver#delete ContentResolver.delete()}. 862 <a href="#Injection"> </a>. 863 </p> 864 <!-- Provider Data Types --> 865 <h2 id="DataTypes"> </h2> 866 <p> 867 . 868 , : 869 </p> 870 <ul> 871 <li> 872 ; 873 </li> 874 <li> 875 (long); 876 </li> 877 <li> 878 ; 879 </li> 880 <li> 881 (double). 882 </li> 883 </ul> 884 <p> 885 , , (BLOB), 886 64- . , get 887 {@link android.database.Cursor}. 888 </p> 889 <p> 890 . 891 892 - {@link android.provider.UserDictionary.Words} ( - 893 <a href="#ContractClasses">-</a>). 894 {@link android.database.Cursor#getType 895 Cursor.getType()}. 896 </p> 897 <p> 898 MIME URI . 899 , 900 , MIME. 901 MIME , 902 . , {@link android.provider.ContactsContract.Data} 903 MIME , 904 . MIME, URI , 905 {@link android.content.ContentResolver#getType ContentResolver.getType()}. 906 </p> 907 <p> 908 MIME 909 <a href="#MIMETypeReference"> MIME</a>. 910 </p> 911 912 913 <!-- Alternative Forms of Provider Access --> 914 <h2 id="AltForms"> </h2> 915 <p> 916 : 917 </p> 918 <ul> 919 <li> 920 <a href="#Batch"> :</a> 921 {@link android.content.ContentProviderOperation}, 922 {@link android.content.ContentResolver#applyBatch ContentResolver.applyBatch()}. 923 </li> 924 <li> 925 : . 926 {@link android.content.CursorLoader}. 927 928 <a href="{@docRoot}guide/components/loaders.html"></a>. 929 </li> 930 <li> 931 <a href="#Intents"> :</a> , 932 , , 933 . 934 </li> 935 </ul> 936 <p> 937 . 938 </p> 939 <h3 id="Batch"> </h3> 940 <p> 941 , , 942 , 943 ( ). 944 </p> 945 <p> 946 947 {@link android.content.ContentProviderOperation}, 948 949 {@link android.content.ContentResolver#applyBatch ContentResolver.applyBatch()}. 950 <em></em> , URI . 951 {@link android.content.ContentProviderOperation} 952 . {@link android.content.ContentResolver#applyBatch 953 ContentResolver.applyBatch()} . 954 </p> 955 <p> 956 - {@link android.provider.ContactsContract.RawContacts} 957 , . <code>ContactAdder.java</code> 958 <a href="{@docRoot}resources/samples/ContactManager/index.html"> </a> 959 960 . 961 </p> 962 <div class="sidebox-wrapper"> 963 <div class="sidebox"> 964 <h2> </h2> 965 <p> 966 <em> </em> , - 967 . , 968 {@link android.content.Intent#ACTION_VIEW}, . 969 . 970 971 <a href="{@docRoot}guide/topics/providers/calendar-provider.html"> </a>. 972 </p> 973 <p> 974 , , 975 . , 976 , {@link android.content.Intent#ACTION_VIEW}, 977 URI , . 978 </p> 979 </div> 980 </div> 981 <h3 id="Intents"> </h3> 982 <p> 983 . 984 , , 985 , , 986 , . 987 </p> 988 <h4> </h4> 989 <p> 990 , 991 , , , 992 , URI. 993 URI , , 994 . , , 995 : 996 </p> 997 <ul> 998 <li> 999 <strong> :</strong> 1000 {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION} 1001 </li> 1002 <li> 1003 <strong> :</strong> 1004 {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION} 1005 </li> 1006 </ul> 1007 <p class="note"> 1008 <strong>.</strong> , 1009 URI . URI. 1010 </p> 1011 <p> 1012 URI URI 1013 <code><a href="{@docRoot}guide/topics/manifest/provider-element.html#gprmsn">android:grantUriPermission</a></code> 1014 1015 <code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>, 1016 1017 1018 <code><a href="{@docRoot}guide/topics/manifest/grant-uri-permission-element.html"><grant-uri-permission></a></code> 1019 1020 <code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>. URI 1021 <a href="{@docRoot}guide/topics/security/security.html"> </a> 1022 URI. 1023 </p> 1024 <p> 1025 , , 1026 {@link android.Manifest.permission#READ_CONTACTS}. , 1027 , . 1028 {@link android.Manifest.permission#READ_CONTACTS}, 1029 , , 1030 . . 1031 </p> 1032 <ol> 1033 <li> 1034 , 1035 {@link android.content.Intent#ACTION_PICK} MIME 1036 {@link android.provider.ContactsContract.RawContacts#CONTENT_ITEM_TYPE} , 1037 {@link android.app.Activity#startActivityForResult 1038 startActivityForResult()}. 1039 </li> 1040 <li> 1041 1042 , . 1043 </li> 1044 <li> 1045 1046 . , 1047 {@link android.app.Activity#setResult setResult(resultcode, intent)} 1048 , . URI 1049 , 1050 {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION} . URI 1051 , 1052 URI . {@link android.app.Activity#finish()}, 1053 . 1054 </li> 1055 <li> 1056 , 1057 {@link android.app.Activity#onActivityResult onActivityResult()} 1058 . , 1059 . 1060 </li> 1061 <li> 1062 URI 1063 , 1064 . 1065 ., . 1066 </li> 1067 </ol> 1068 <h4> </h4> 1069 <p> 1070 , 1071 , , . 1072 </p> 1073 <p> 1074 , 1075 {@link android.content.Intent#ACTION_INSERT}, 1076 . , 1077 . , 1078 1079 {@link android.content.Intent#ACTION_INSERT} . 1080 </p> 1081 <!-- Contract Classes --> 1082 <h2 id="ContractClasses">-</h2> 1083 <p> 1084 - , URI , 1085 , . - 1086 ; 1087 . , Android, 1088 - {@link android.provider}. 1089 </p> 1090 <p> 1091 , - 1092 {@link android.provider.UserDictionary}, URI . URI 1093 words 1094 {@link android.provider.UserDictionary.Words#CONTENT_URI UserDictionary.Words.CONTENT_URI}. 1095 {@link android.provider.UserDictionary.Words} , 1096 , . , 1097 : 1098 </p> 1099 <pre> 1100 String[] mProjection = 1101 { 1102 UserDictionary.Words._ID, 1103 UserDictionary.Words.WORD, 1104 UserDictionary.Words.LOCALE 1105 }; 1106 </pre> 1107 <p> 1108 - {@link android.provider.ContactsContract} . 1109 . , 1110 {@link android.provider.ContactsContract.Intents.Insert}, -, 1111 . 1112 </p> 1113 1114 1115 <!-- MIME Type Reference --> 1116 <h2 id="MIMETypeReference"> MIME</h2> 1117 <p> 1118 MIME, MIME, . 1119 </p> 1120 <p> 1121 MIME : 1122 </p> 1123 <pre> 1124 <em>type</em>/<em>subtype</em> 1125 </pre> 1126 <p> 1127 , MIME <code>text/html</code> <code>text</code> 1128 <code>html</code>. URI, , 1129 , URI, HTML. 1130 </p> 1131 <p> 1132 MIME, MIME , 1133 <em></em> <em></em>. <em></em> : 1134 </p> 1135 <pre> 1136 vnd.android.cursor.<strong>dir</strong> 1137 </pre> 1138 <p> 1139 , 1140 </p> 1141 <pre> 1142 vnd.android.cursor.<strong>item</strong> 1143 </pre> 1144 <p> 1145 . 1146 </p> 1147 <p> 1148 <em></em> . Android 1149 . , , 1150 MIME : 1151 </p> 1152 <pre> 1153 vnd.android.cursor.item/phone_v2 1154 </pre> 1155 <p> 1156 , <code>phone_v2</code>. 1157 </p> 1158 <p> 1159 1160 . , , . 1161 <code>com.example.trains</code>, 1162 Line1, Line2 Line3. URI 1163 </p> 1164 <p> 1165 <pre> 1166 content://com.example.trains/Line1 1167 </pre> 1168 <p> 1169 Line1 MIME 1170 </p> 1171 <pre> 1172 vnd.android.cursor.<strong>dir</strong>/vnd.example.line1 1173 </pre> 1174 <p> 1175 URI 1176 </p> 1177 <pre> 1178 content://com.example.trains/Line2/5 1179 </pre> 1180 <p> 1181 5 Line2 MIME 1182 </p> 1183 <pre> 1184 vnd.android.cursor.<strong>item</strong>/vnd.example.line2 1185 </pre> 1186 <p> 1187 - MIME. , - 1188 {@link android.provider.ContactsContract.RawContacts} 1189 1190 {@link android.provider.ContactsContract.RawContacts#CONTENT_ITEM_TYPE} MIME 1191 . 1192 </p> 1193 <p> 1194 URI 1195 <a href="#ContentURIs">URI </a>. 1196 </p> 1197