内容提供者获取UserDicationary不返回任何内容 [英] Content Provider to get UserDicationary returns nothing

查看:80
本文介绍了内容提供者获取UserDicationary不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用它来添加一些单词

I tried using this to add some words

UserDictionary.Words.addWord(getActivity().getApplicationContext(),"DROIDODD",11,null,null);

现在光标包含这个单词,但是我该如何在个人词典中访问其他单词,android在哪里存储我们通过键盘输入的新单词?在这个数据存储区中,那么词典内容提供者为什么不访问那些?

Now the cursor contains this word , but how do i access my other words in the personal dictionay , Where does android store the new words we enter through keyboards ? Is in in this datastore ,then why doesnt the dictionary content provider access those?

我正在尝试使用内容解析器获取并显示android用户词典中的单词,问题是返回的游标不包含任何值,游标计数为0,我想获取用户词典中的所有单词,然后将其附加到片段中的textVIew中

I am trying to get and display the words in the android user dictionary using a content resolver ,Problem is the returned cursor does not contain any values , the cursor count is 0 , I want get all the Words in the user dictionary and simply append it to a textVIew inside my fragment

Fragment.java代码如下所示:

The Fragment.java code is shown below :

package com.sweetapps.managephonedictionary;

import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.UserDictionary;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * A placeholder fragment containing a simple view.
 */
public class MainActivityFragment extends Fragment {

    private  String details="The words in your personal dictionary are \n\n";

    public MainActivityFragment() {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v("myLog","Inside Oncreate");
        //content provider code
        ContentResolver contentResolver= getActivity().getApplicationContext().getContentResolver();
        //get all details
        Cursor cursor=contentResolver.query(UserDictionary.Words.CONTENT_URI,null,null,null,null );
       Log.v("myLog",cursor.getCount()+"");

        while (cursor.moveToNext())
        {
            details=details+cursor.getString(cursor.getColumnIndex(UserDictionary.Words.WORD));
            Log.v("myLog",cursor.getString(cursor.getColumnIndex(UserDictionary.Words.WORD)));
        }

    cursor.close();


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view= inflater.inflate(R.layout.fragment_main, container, false);

        TextView textView= (TextView) view.findViewById(R.id.wordsTextView);
        textView.setText(details);
        return view;
    }
}

我的输出仅为个人词典中的单词是

我的logcat是

 V/myLog﹕ Inside Oncreate
 V/myLog﹕ 0

我要去哪里了,我确定我的电话词典中有很多单词,我在多种设备上都尝试过,但还是一样.请帮忙!

Where am i going wrong , I am sure my phone dictionary has quite a few words, i tried it on multiple device , still the same . Please help!

推荐答案

我在三星设备上有类似的问题,似乎三星(由于某种原因)已经覆盖了用户词典...我从剧本中安装了Google键盘存储,其中有一个选项可以向词典中添加单词,当打开用户词典时,我发现它为空,并且按添加单词根本没有任何响应,除了系统声音:).

I have similar problem on my Samsung devices, it seems that Samsung (for some reason) has overridden the user dictionary... I installed google keyboard from the play store which has an option for adding words to the dictionary, when opening the user dictionary, I find it empty and pressing add words yield no response at all, except for the system sound :).

如果您像我一样,尝试对内容提供商进行试验,并发现用户词典是一个简单的目标,那么切换到用户联系人就一样简单.

If you are like me, trying to experiment with content providers and found that user dictionary is an easy target, it is just as simple to switch to user contacts.

首先更改权限,这样您就可以访问通讯录

First change permissions so that you have access to Contacts instead

<uses-permission android:name="android.permission.READ_CONTACTS"/>

然后按如下所示更改内容解析器:

Then change your content resolver as follows:

Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
int wordColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);

这使我完成了其余的实验或运动..

This got me going through the rest of experimentation, or exercise..

这篇关于内容提供者获取UserDicationary不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆