android contentprovider理解

來源:互聯網
上載者:User

標籤:

內容提供者用於儲存和檢索資料,使android系統中不同應用程式之間可以進行共用資料.以uri的形式對外提供資料.

首先用一個類繼承android.content包下contentprovide,重寫一下方法.

  1.public boolean oncreare()   建立contentprovide時調用.

  2.public int delete(Uri uri, String selection, String[] selectionArgs) 刪除指定資料.

  3.public Uri insert(Uri uri, ContentValues values)  插入資料

  4.public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) 更新指定條件下的資料

  5.public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) 查詢指定條件的資料

  6.public String getType(Uri uri) 返回uri代表資料的MIME類型 

其次寫uri,由content://authorities/path

  authorities指在資訊清單檔中註冊的android:authorities的值

  path代表資料,動態改變

如:

 private static UriMatcher matcher=new UriMatcher(UriMatcher.NO_MATCH);    private static final int INSERT=1;    private static final int DELETE=2;    private static final int UPDATE=3;    private static final int QUERY=4;    private static final int QUERYONE=5;    static {        matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","insert",INSERT);        matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","delete",DELETE);        matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","update",UPDATE);        matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","query",QUERY);        //#為萬用字元,所有符合"query/"的都返回queryone的返回碼        matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","query/#",QUERYONE);    }

public int match(Uri uri)  返回addUri方法中傳入的參數的code值

android contentprovider理解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.