The Podcast at Delphi.org

Beyond being the longest running podcast about Object Pascal and Delphi programming languages, tools, news, and community, this is also Jim McKeeth's blog on other things related to programming and technology.

2015-08-07

Adding to the Android User Dictionary

by Jim McKeeth

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):

[delphi light=”true”]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; [/delphi]

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.

tags: News