我在网上搜索并研究了这个问题,但没有得到明确的答案。我已经使用内容提供者将单词添加到用户字典中,因为android 文档指出这些单词被添加,但是之后当我在键盘上键入时,我看不到该单词出现在候选视图中的建议中,因为我们点击了其他单词下次出现在那里。我真的很感激这个问题的完整答案,因为很多人在网上问这个问题而没有得到回答。我试过这个
Uri mNewUri;
// Defines an object to contain the new values to insert
ContentValues mNewValues = new ContentValues();
// Sets the values of each column and inserts the word. The arguments to the "put"
// method are "column name" and "value"
mNewValues.put(UserDictionary.Words.APP_ID, "example.user");
mNewValues.put(UserDictionary.Words.LOCALE, "en_US");
mNewValues.put(UserDictionary.Words.WORD, "Qasim");
mNewValues.put(UserDictionary.Words.FREQUENCY, "100");
mNewUri = getContentResolver().insert(
UserDictionary.Words.CONTENT_URI, // the user dictionary content URI
mNewValues // the values to insert
);
Uri dic = UserDictionary.Words.CONTENT_URI;
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(dic, null, null, null, null);
//here i retrieve all the words stored into my dictionary
while (cursor.moveToNext()){
String word = cursor.getString(cursor.getColumnIndex(UserDictionary.Words.WORD));
int id = cursor.getInt(cursor.getColumnIndex(UserDictionary.Words._ID));
String app = cursor.getString(cursor.getColumnIndex(UserDictionary.Words.APP_ID));
int frequency = cursor.getInt(cursor.getColumnIndex(UserDictionary.Words.FREQUENCY));
String locale = cursor.getString(cursor.getColumnIndex(UserDictionary.Words.LOCALE));
Log.i("", "word: "+word+"\nId: "+id+"\nAppID: "+app+"\nfrequency: "+frequency+"\nLocale:"+locale);
}
如果有人在这里帮助我,将不胜感激