如何在Android上查询UserDictionary内容提供程序?

use*_*715 8 android

我似乎找不到任何关于如何在给定单词的情况下查询UserDictionary内容提供者的良好示例代码.我的查询如下:

Cursor cur = getContentResolver().query(
    UserDictionary.Words.CONTENT_URI,
    new String[] {Words._ID, Words.WORD},
    Words.WORD + "=?",
    new String[] {"test"},
    null);
Run Code Online (Sandbox Code Playgroud)

我也尝试过不指定查询以及不指定投影,并且光标始终为空.我已经列入android.permission.READ_USER_DICTIONARY了我的清单.

bin*_*ary 1

尝试这个

final String[] QUERY_PROJECTION = {
  UserDictionary.Words._ID,
  UserDictionary.Words.WORD
};
Cursor cursor = getContentResolver()
            .query(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, "(locale IS NULL) or (locale=?)", 
            new String[] { Locale.getDefault().toString() }, null);
Run Code Online (Sandbox Code Playgroud)

我没有测试过这个,只是一个建议