【发布时间】:2017-08-17 01:06:05
【问题描述】:
我正在尝试制作与 android 开发人员指南中类似的 ContentProvider 读数 - 从用户字典中读取。我不明白为什么我的光标总是有 0 行。当然我已经添加了所需的权限。我试图将空值更改为空数组或类似的东西,但它不起作用。 有什么想法吗?
有我的源代码
public void sampleMethodWithContentProviders() {
// String contentUriStr = "content://user_dictionary/words";
// Uri wordsUri = Uri.parse(contentUriStr);
String[] projectionString = {
UserDictionary.Words._ID,
UserDictionary.Words.WORD,
UserDictionary.Words.LOCALE
};
String selectClause = null;
String[] selectArgs = null;
String order = null;
Cursor cursor = getContentResolver().query(UserDictionary.Words.CONTENT_URI, projectionString, selectClause, selectArgs, order);
Log.i("Cursor", cursor == null ? "null" : "obiekt");
for (String s : cursor.getColumnNames())
Log.i("Cursor column name: ", s);
Log.i("Num of cursor element: ", Integer.toString(cursor.getCount()));
while (cursor.moveToNext())
Log.i("a", "b");
}
还有日志结果
12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/光标:obiekt 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/光标列名:: _id 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/光标列名:: word 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/光标列名:: 语言环境 12-01 00:02:54.530 11693-11693/com.kros.withoutpain 光标元素的 I/Num:: 0
【问题讨论】:
-
输入法不需要使用
UserDictionaryProvider,许多输入法依赖于他们自己的内部列表或数据库。如果您的设备上没有使用 Provider 的键盘,那么您的字典很可能是空的。 -
你是在真机还是模拟器上测试?字典有没有可能是空的
-
@FletcherJohns-我正在设备上进行测试,问题可能如上面评论中所述-索尼正在预装 xperia 专用键盘。
标签: android android-contentresolver