本例中,对 表content://user_dictionary/words 的查询需要请求写入访问权限
即在manifest中添加
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
本例中contentResolver ---> 系统提供的contentProvider
增加记录
@Override
public void onClick(View view) {
// 这个对象对应一行数据,相当于sql:insert into table1(xx,xx) values(xx,xx)
ContentValues newValues = new ContentValues();
/*
* 设置每列的值。
* “put”方法的参数是“列名”和“值”
*/
newValues.put(UserDictionary.Words.APP_ID, "example.user");
newValues.put(UserDictionary.Words.LOCALE, "en_US");
newValues.put(UserDictionary.Words.WORD, "insert");
newValues.put(UserDictionary.Words.FREQUENCY, "100");
//插入方法,返回null表示插入失败;插入成功则返回新行的uri,格式content://user_dictionary/w