[Android] Content Providers (Arrange)

Using Content Providers

使用 android.provider package的物件

使用URI:
  • Querying for Data 查詢資料
content://contacts/people/ 這種寫法,會列出所有資料
content://contacts/people/23 這種寫法,只會回傳ID=23這筆資料
  • Modifying Data 修改資料
呼叫ContentResolver.update()
  • Adding a Record 增加資料
呼叫ContentResolver.insert()
若要儲存檔案,要呼叫ContentResolver().openOutputStream()。
  • Deleting a Record 刪除資料
呼叫ContentResolver.delete()
刪除多筆記錄時,呼叫ContentResolver.delete()裡的android.provider.Contacts.People.CONTENT_URI

Creating Content Providers
  • 繼承ContentProvider
  • 定義一個public static final Uri 命名為CONTENT_URI。這個字串要以content://為標準,你的content provider才可以運作。
  • 使用content providers儲存資料或使用SQLite資料庫儲存資料。
  • Android的Provider,SQLiteOpenHelper的CLASS會幫助你建立和管理資料庫。
  • 如果你要顯示如bitmap檔案,應該使用content:// URI的語法。EX:content://media/internal/images or content://media/external/images
  • 如果你要管理一個新的資料型態,你必須先定義一個android.ContentProvider.getType(url),新的MIME型態。
修改自:

Comments

Popular posts from this blog

[Linux] UVC Camera

UPnP Device Implementations

[UPnP] UPnP Implementers Corporation & UPnP Forum