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

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