Adding to the Android User Dictionary

On Android there is a single UserDictionary that works across all keyboards, and any app (with the appropriate permissions) can query, add and remove words. Here is some simple code to add a word to the dictionary (via XE8):

uses<br />
  Androidapi.JNI.Provider, Androidapi.Helpers, Androidapi.JNI.JavaTypes;</p>
<p>procedure AddUserWord(const AWord: string);<br />
begin<br />
  // Need WRITE_USER_DICTIONARY permission<br />
  TJUserDictionary_Words.JavaClass.addWord(<br />
    SharedActivityContext, // Context<br />
    StringToJString(AWord),// Word to add<br />
    255,                   // Frequency: 1- 255<br />
    nil,                   // optional shortcut<br />
    SharedActivityContext.getResources.getConfiguration.locale<br />
    );<br />
end;<br />

If you also want to read the dictionary then you need to have the READ_USER_DICTIONARY permission. Check out the documentation for more information on the UserDictionary and it’s Words list.

This entry was posted in Android. Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.