内容提供商

时间:2011-05-11 10:09:19

标签: java android android-contentprovider

我创建了扩展contentprovider的类。 我已经覆盖了6个函数

@override
public Uri insert(Uri uri, ContentValues initialvalues) {

    ContentValues values;
    if(initialvalues != null){
        values = new ContentValues(initialvalues);
    }else{
        values = new ContentValues();
    }
    SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
    long rowId = mDb.insert(DatabaseHelper.TABLE_PROGRAM, null, values);
    if(rowId > 0){
        Uri programUri = ContentUris.withAppendedId(null, rowId);
        getContext().getContentResolver().notifyChange(programUri, null);
        return programUri;
    }
    throw new IllegalArgumentException("Failed to insert row into " + uri);
}

private void createdata(){
    String a = "a", b = "b", c = "c", d= "d";
    //how i going to call the content provider to let me to add in data?
}

我的问题是如何调用insert()来添加数据?

1 个答案:

答案 0 :(得分:1)

通过getContentResolver()insert方法获取ContentResolver实例。

更新 That's the best tutorial

相关问题