您好,登錄后才能下訂單哦!
package com.android.provider;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
public class HelloContentProvider extends ContentProvider{
private static final UriMatcher um=new UriMatcher(UriMatcher.NO_MATCH);
private SQLiteDatabase sqlLite;
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onCreate() {
// TODO Auto-generated method stub
um.addURI("com.android.provider","book",1);
sqlLite=SQLiteDatabase.openDatabase("/data/data/com.android.provider/tt", null,SQLiteDatabase.OPEN_READWRITE|SQLiteDatabase.CREATE_IF_NECESSARY);
sqlLite.execSQL("create table books([id] Integer primary key.autoincrement not null,[bookname] varchar(30) not null)");
ContentValues cv=new ContentValues();
cv.put("bookname", "android開(kāi)發(fā)");
sqlLite.insert("books", null, cv);
return false;
}
@Override
public Cursor query(Uri uri, String[] arg1, String arg2, String[] arg3,
String arg4) {
// TODO Auto-generated method stub
if(um.match(uri)==1){
Cursor cursor=sqlLite.query("books", null, null, null, null, null, null);
return cursor;
}else{
return null;
}
}
@Override
public int update(Uri uri, ContentValues values, String arg2, String[] arg3) {
// TODO Auto-generated method stub
if(um.match(uri)==1){
int result=sqlLite.update("books", values, null, null);
}
return 0;
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。