close

Content Providers 概略介紹

官方網址:http://code.google.com/android/devel/data/contentproviders.html

 

{概要}

1.它是在應用程式裡,存取物件的方法。
2.若你的資料想成為可公開使用的,你可以製造或呼叫一個content provider。  
3.在android裡是有一些content providers是公開的資料型態 ,例如: audio, video, images, personal contact information(如通訊錄)…. 
4.可以在provider package裡,看到android原本就有提供的content providers。

 

Content Providers 可分兩類:

1.使用Content Providers

2.建立Content Providers

 

********************************************************************

{使用Content Providers}

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

 

{建立Content Providers}

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

arrow
arrow
    文章標籤
    android content provider
    全站熱搜

    虎虎 發表在 痞客邦 留言(0) 人氣()