0

When you type in any text area OS wide in Android (not only in my app) the user could use auto correct or click the misspelled word to correct it. Is there a way to get a list of all the misspelled words and what they were turned into?.

Alternatively, is this possible with a rooted device or can you even replace autocorrect with your own dictionary to track this?

hiashutoshsingh
  • 980
  • 2
  • 14
  • 41
Jimmy
  • 10,427
  • 18
  • 67
  • 122

2 Answers2

2

This functionality present in Android is provided by the Spell Checker Framework. Its documentation here and here shows how you can connect to it and interact with it's suggestions inside an app.

Because this is a service provided by the system, much like something such as Location Services, there isn't a way to hook into it system-wide without being rooted. I don't have any personal experience tinkering with the inner workings of the Android system or its services, but as a starting point, you could take a look into any open source apps that tamper with the input/output of some of these services e.g. GPS spoofing apps.

Worst case scenario would be you'd have to locate where the Spell Checker Framework compiles to and is stored, and overwrite it with a modified version that does what you want.

I was able to find an older version of SpellCheckerService.java here from Android 5.1.1. You might be able to look into this and figure out what you need to do and where.

EDIT: After checking out the entire list of 1149 Android source repos (100+ GB), I found the two most likely candidates for you to scour for an opening.

git clone https://android.googlesource.com/platform/frameworks/base

git clone https://android.googlesource.com/platform/packages/inputmethods/LatinIME

In base, you'll find the SpellChecker sources in base/core/java/android/****/textservice/, where **** is one of service, view, widget, or internal (internal is in com/android). This appears to be the lowest level. Many of the methods and such here are abstract.

In LatinIME, you'll find the higher level SpellChecker sources for the latin character set (there are other repos for other charsets). You will find them in LatinIME/java/src/com/android/inputmethod/latin/spellcheck/. This is where you'll find the implementations.

After tracing through the sources (specifically tracing getSuggestionResults), the calls go down to the Dictionary level. LatinIME/java/src/com/android/inputmethod/latin/Dictionary.java has abstract public ArrayList<SuggestedWordInfo> getSuggestions() which means that it is the Dictionary's responsibility to return the results. Still, I would assume that a user installable dictionary is just a simple database which is used by the Android system's Dictionary handling code, which likely means you are still going to need to modify system code and be rooted to accomplish your goal.

I'm afraid this is as far down the rabbit hole as I go on the subject. I fear I have not completely answered the question, but this should give you some direction on how you want to proceed.

YET ANOTHER EDIT: Maybe I'm wrong about an installable dictionary just being a database. See this example. This example appears to be in the form of an app though, so I am not sure.

RayfenWindspear
  • 6,116
  • 1
  • 30
  • 42
  • Looking for the actual source for SpellCheckerService. It's surprisingly difficult to locate... I'm hoping it might shed some light on possible solutions – RayfenWindspear Feb 13 '17 at 17:25
  • Interesting, so I assume Android will query the service with the misspelled word so the service could return a list of options. Now I wonder if the OS will notify the service of what the user selected (which could improve the spell checker). Let me know if you think my assumption is correct. Thanks! Btw I found this link trying to get more info https://android-developers.googleblog.com/2012/08/creating-your-own-spelling-checker.html – Jimmy Feb 13 '17 at 17:34
  • The Android source repo is separated into 1149 separate repositories which are apparently not searchable on the web :@ Lucky for me, I built a scraper a while back which allowed me to pull all the git clone commands in seconds. Now I'm just waiting for all 1149 individual repos to download... – RayfenWindspear Feb 13 '17 at 18:11
  • Oh that's a lot, really appreciate the help. I'll keep looking at the docs/other resources I might find something. – Jimmy Feb 13 '17 at 18:24
  • Found an old version of SpellCheckerService.java you can look over to see how it works. http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/service/textservice/SpellCheckerService.java?av=f – RayfenWindspear Feb 13 '17 at 18:42
  • @Jimmy I'm afraid the news is not good. Unless installable dictionaries actually are installable Java implementations of Dictionary, you are stuck with modifying system files to accomplish your goals. – RayfenWindspear Feb 13 '17 at 21:18
  • Thank you very much for your efforts, great answer with very helpful details. I'm going use the info you provided and investigate further. – Jimmy Feb 17 '17 at 16:58
0

To find suggestion of Typed text

Spannable str = myEditText.getText(); 
SuggestionSpan[] spanned = str.getSpans(startIndex, endIndex, SuggestionSpan.class);

If spanned is not empty, there is an error in the text between startIndex and endIndex. By changing the values of these indices, it will be possible to find which word is erroneous. Each item in the spanned array has a field called mSuggestions, which is an array of strings and provides the suggested words for the erroneous word.

There is other method to check for: here

Community
  • 1
  • 1
Hemanth S
  • 669
  • 6
  • 16