【问题标题】:User Dictionary ContentResolver query returns 0 rows cursor用户字典 ContentResolver 查询返回 0 行游标
【发布时间】: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

【问题讨论】:

  • 输入法不需要使用UserDictionary Provider,许多输入法依赖于他们自己的内部列表或数据库。如果您的设备上没有使用 Provider 的键盘,那么您的字典很可能是空的。
  • 你是在真机还是模拟器上测试?字典有没有可能是空的
  • @FletcherJohns-我正在设备上进行测试,问题可能如上面评论中所述-索尼正在预装 xperia 专用键盘。

标签: android android-contentresolver


【解决方案1】:

从 API 23 开始从 Android 中删除了对用户字典的访问,请参阅 this bug report...this stack overflow question...

这似乎已被关闭,因为“按预期工作”似乎对该功能有一些滥用,因此已将其删除。

如果您正在尝试使用模拟器,您可能想尝试使用带有更早版本的 APK 的模拟器。但是,我回滚到 21 岁(棒棒糖)时运气不佳。如果您只是想尝试使用游标和内容解析器,那么我建议您使用 Muhammad Farag's answer to a similar question

【讨论】:

  • 哇,这是 2015 年提出的问题 :-) 无论如何 - 尽管有任何可能测试或检查此问题,但感谢您的参与 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
相关资源
最近更新 更多