Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove words from UserDictionary?

With UserDictionary.Words and WRITE_USER_DICTIONARY permission it's possible to add words to the user dictionary, but I don't see any way to remove words.

The motivation in this case is to add autocompletion suggests that are local to the app and remove them when exiting the app, but I can also imagine something like an app that automatically removed typos that were accidentally added.

Is there any way to do this?

like image 827
blahdiblah Avatar asked Nov 15 '13 00:11

blahdiblah


1 Answers

One possible solution is to remove the exact word(s) using ContentResolver.delete(). Example:

private int deleteWord(String word) {
    if (TextUtils.isEmpty(word)) {
        return -1;
    }

    return getContentResolver().delete(UserDictionary.Words.CONTENT_URI,
            UserDictionary.Words.WORD + "=?", new String[] { word });
}

And of course, need

<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />

defined in the manifest.

Hope this helps.

like image 129
ozbek Avatar answered Sep 30 '22 14:09

ozbek