Prerequisite: Make sure you have the appropriate words in the UserDictionary on
Settings → Language & Input → Personal dictionary .
A sample sql query that searches for words containing SO in a user dictionary, and an equivalent Android code sample. Pay attention to use ? to replace with args .
SQL query:
SELECT UserDictionary.Words._ID, UserDictionary.Words.WORD FROM UserDictionary.Words.CONTENT_URI WHERE UserDictionary.Words.WORD LIKE "%SO%
Equivalent code:
String[] columns = {UserDictionary.Words._ID, UserDictionary.Words.WORD}; String condition = UserDictionary.Words.WORD + " LIKE ? "; // ? in condition will be replaced by `args` in order. String[] args = {"%SO%"}; ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, columns, condition, args, null); //Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, projection, null, null, null); - get all words from dictionary if ( cursor != null ) { int index = cursor.getColumnIndex(UserDictionary.Words.WORD); //iterate over all words found while (cursor.moveToNext()) { //gets the value from the column. String word = cursor.getString(index); Log.i(TAG, "Word found: " + word); } }
Permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/> sub>
Kiran
source share