Java 获取UserDictionary的内容提供程序不返回任何内容
编辑:我试着用这个来添加一些单词Java 获取UserDictionary的内容提供程序不返回任何内容,java,android,dictionary,android-contentprovider,Java,Android,Dictionary,Android Contentprovider,编辑:我试着用这个来添加一些单词 UserDictionary.Words.addWord(getActivity().getApplicationContext(),"DROIDODD",11,null,null); 现在光标包含了这个单词,但是我如何访问个人词汇表中的其他单词, android在哪里存储我们通过键盘输入的新词? 在这个数据存储中,那么为什么字典内容提供者不访问这些内容呢 我正在尝试使用内容解析器获取并显示android用户词典中的单词,问题是返回的游标不包含任何值,游标计数
UserDictionary.Words.addWord(getActivity().getApplicationContext(),"DROIDODD",11,null,null);
现在光标包含了这个单词,但是我如何访问个人词汇表中的其他单词,
android在哪里存储我们通过键盘输入的新词?
在这个数据存储中,那么为什么字典内容提供者不访问这些内容呢
我正在尝试使用内容解析器获取并显示android用户词典中的单词,问题是返回的游标不包含任何值,游标计数为0,
我想获得用户词典中的所有单词,并简单地将其附加到片段中的textVIew中
Fragment.java代码如下所示:
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;
}
}
我的输出仅为您个人词典中的单词为
我的日志是
V/myLog﹕ Inside Oncreate
V/myLog﹕ 0
我错在哪里呢?我肯定我的手机字典里有很多单词,我在多个设备上都试过了,还是一样。
请帮忙 我的三星设备也有类似的问题,似乎三星(出于某种原因)已经覆盖了用户词典。。。我从play store安装了google键盘,它有一个向字典添加单词的选项,当打开用户字典时,我发现它是空的,按add words根本没有响应,除了系统声音:)
如果您和我一样,尝试使用内容提供商并发现用户字典是一个容易的目标,那么切换到用户联系人也同样简单
首先更改权限,以便您可以访问联系人
<uses-permission android:name="android.permission.READ_CONTACTS"/>
这让我完成了剩下的实验或练习。首先,我们需要检查我们的个人词典是否是空的
我用这个来得到结果:
在你的手机里
查找并点击设置>语言和输入>个人词典>添加或+(加号)图标。并添加一个单词。现在尝试运行程序或应用程序
字典是空的,当我添加一些值时,它返回结果
对于不同版本的android
我为索尼使用了上面的链接
同样,你可以找到如何为其他手机添加字典。非常感谢,我以为我做错了什么,结果是三星的问题(或错误:)我刚刚读了一篇关于“Android碎片化”的文章。作者的意思是,开发人员不仅要关注许多版本或api级别,还要关注不同的制造商、定制、硬件和软件差异:)
Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
int wordColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);