EDIT: I tried using this to add some words
UserDictionary.Words.addWord(getActivity().getApplicationContext(),"DROIDODD",11,null,null);
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?
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
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;
}
}
My output is only The words in your personal dictionary are
My logcat is
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!
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..