似乎它应该工作。导入后我可以在设置中的用户词典中看到单词。
public static void addWord(Context context, String word, Locale locale) {
final int COLUMN_COUNT = 5;
ContentValues values = new ContentValues(COLUMN_COUNT);
values.put(UserDictionary.Words.WORD, word);
values.put(UserDictionary.Words.FREQUENCY, DEFAULT_FREQUENCY);
values.put(UserDictionary.Words.LOCALE, null == locale ? null : locale.toString());
values.put(UserDictionary.Words.APP_ID, 0); // TODO: Get App UID
values.put(UserDictionary.Words.SHORTCUT, "");
resovler.insert(UserDictionary.Words.CONTENT_URI, values);
}
}
但相反,谷歌键盘会出现此错误(我可以在logcat中看到它)
Process: com.google.android.inputmethod.latin, PID: 30183
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at com.android.inputmethod.latin.makedict.FusionDictionary.add(FusionDictionary.java:486)
at com.android.inputmethod.latin.makedict.FusionDictionary.add(FusionDictionary.java:401)
at com.android.inputmethod.latin.DictionaryWriter.addUnigramWord(DictionaryWriter.java:72)
at com.android.inputmethod.latin.ExpandableBinaryDictionary.addWord(ExpandableBinaryDictionary.java:273)
at com.android.inputmethod.latin.UserBinaryDictionary.addWords(UserBinaryDictionary.java:253)
at com.android.inputmethod.latin.UserBinaryDictionary.loadDictionaryAsync(UserBinaryDictionary.java:181)
at com.android.inputmethod.latin.ExpandableBinaryDictionary.writeBinaryDictionary(ExpandableBinaryDictionary.java:542)
at com.android.inputmethod.latin.ExpandableBinaryDictionary.access$700(ExpandableBinaryDictionary.java:48)
at com.android.inputmethod.latin.ExpandableBinaryDictionary$12.run(ExpandableBinaryDictionary.java:630)
at com.android.inputmethod.latin.utils.PrioritizedSerialExecutor$1.run(PrioritizedSerialExecutor.java:70)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
在这次崩溃之后,一切似乎都有效。拼写检查器可以看到导入的单词。
答案 0 :(得分:0)
问题显然是以某种方式在字典中添加空字符串。